這個(gè)系列主要寫一些平時(shí)ios開發(fā)和學(xué)習(xí)過程中所記錄的問題、隨筆和解決方法,我會(huì)盡量用更多的截圖或者gif圖來還原我的開發(fā)現(xiàn)場,在執(zhí)行個(gè)人備忘錄功能的同時(shí)希望對(duì)你有所幫助。
1.背景
移動(dòng)操作系統(tǒng)的app容易受到來電或者鎖屏等干擾,在app受到干擾時(shí)會(huì)產(chǎn)生一些系統(tǒng)事件,這時(shí)UIApplication會(huì)通知它的delegate對(duì)象,讓代理來處理這些系統(tǒng)事件
2.AppDelegate方法含義
//1.應(yīng)用程序啟動(dòng)完畢時(shí)調(diào)用
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
? ? // Override point for customization after application launch.
? ? return YES;
}
//2.應(yīng)用程序?qū)⒁ソ裹c(diǎn)時(shí)調(diào)用
- (void)applicationWillResignActive:(UIApplication *)application {
? ? // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
? ? // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
//3.應(yīng)用程序進(jìn)入后臺(tái)時(shí)調(diào)用
- (void)applicationDidEnterBackground:(UIApplication *)application {
? ? // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
? ? // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
//4.應(yīng)用程序進(jìn)入前臺(tái)時(shí)調(diào)用
- (void)applicationWillEnterForeground:(UIApplication *)application {
? ? // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
//5.應(yīng)用程序獲取焦點(diǎn)
- (void)applicationDidBecomeActive:(UIApplication *)application {
? ? // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
//6.應(yīng)用程序退出時(shí)調(diào)用
- (void)applicationWillTerminate:(UIApplication *)application {
? ? // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
注意:失去焦點(diǎn)的意思是不能與用戶進(jìn)行交互
