IOS初學-生命週期
阿新 • • 發佈:2018-11-12
這裡主要是記錄ios的生命週期
執行專案之後可以進行 開啟 退出到後臺。喚醒 鎖屏 後臺清除等操作,觀察在xcode中打出的log來理解每個方法的呼叫時機
funcapplication(_application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool{ // Override point for customization after application launch. print(">>>>>>>>>>>>>>程式載入完成"); returntrue } funcapplicationWillResignActive(_application: UIApplication) { // 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. print(">>>>>>>>>>>>>>程式進入非活動狀態。不在接收訊息和事件"); } funcapplicationDidEnterBackground(_application: UIApplication) { // 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. print(">>>>>>>>>>>>>>程式進入後臺,進入後臺仍要進行操作在此處新增"); } funcapplicationWillEnterForeground(_application: UIApplication) { // 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. print(">>>>>>>>>>>>>>程式在後臺時,將要回到前臺時呼叫此方法"); } funcapplicationDidBecomeActive(_application: UIApplication) { // 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. print(">>>>>>>>>>>>>程式進入活動狀態將執行此方法"); } funcapplicationWillTerminate(_application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. print(">>>>>>>>>>>>>程式將要推出執行此方法對資料和檔案清除在此處呼叫"); }