91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

iOS學習——iOS應用程序生命周期(四)

發布時間:2020-07-19 17:34:04 來源:網絡 閱讀:310 作者:xyz_lmn 欄目:移動開發

       開發應用程序都要了解其生命周期,開始接觸android時也是從應用程序生命周期開始的,android的應用程序生命周期更多是其組件的生命周期,例如Activity、Service。今天我們接觸一下iOS應用程序的生命周期,

       iOS的入口在main.m文件:

int main(int argc, char *argv[]) {     @autoreleasepool {         return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));     } } 

       main函數的兩個參數,iOS中沒有用到,包括這兩個參數是為了與標準ANSI C保持一致。

       UIApplicationMain函數,前兩個和main函數一樣,重點是后兩個,官方說明是這樣的:

// If nil is specified for principalClassName, the value for NSPrincipalClass from the Info.plist is used. If there is no // NSPrincipalClass key specified, the UIApplication class is used. The delegate class will be instantiated using init. UIKIT_EXTERN int UIApplicationMain(int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName);

       后兩個參數分別表示程序的主要類(principal class)和代理類(delegate class)。如果主要類(principal class)為nil,將從Info.plist中獲取,如果Info.plist中不存在對應的key,則默認為UIApplication;如果代理類(delegate class)將在新建工程時創建。

       根據UIApplicationMain函數,程序將進入AppDelegate.m,這個文件是xcode新建工程時自動生成的。下面看一下AppDelegate.m文件,這個關乎著應用程序的生命周期。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {     self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];     // Override point for customization after application launch.     self.window.backgroundColor = [UIColor whiteColor];     [self.window makeKeyAndVisible];     NSLog(@"iOS_didFinishLaunchingWithOptions");     return YES; }  - (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 throttle down OpenGL ES frame rates. Games should use this method to pause the game.     NSLog(@"iOS_applicationWillResignActive");  }  - (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.     NSLog(@"iOS_applicationDidEnterBackground");  }  - (void)applicationWillEnterForeground:(UIApplication *)application {     // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.     NSLog(@"iOS_applicationWillEnterForeground");  }  - (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.     NSLog(@"iOS_applicationDidBecomeActive");  }  - (void)applicationWillTerminate:(UIApplication *)application {     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.     NSLog(@"iOS_applicationWillTerminate");  } 

     1、application didFinishLaunchingWithOptions:當應用程序啟動時執行,應用程序啟動入口,只在應用程序啟動時執行一次。若用戶直接啟動,lauchOptions內無數據,若通過其他方式啟動應用,lauchOptions包含對應方式的內容。

     2、applicationWillResignActive:在應用程序將要由活動狀態切換到非活動狀態時候,要執行的委托調用,如 按下 home 按鈕,返回主屏幕,或全屏之間切換應用程序等。

     3、applicationDidEnterBackground:在應用程序已進入后臺程序時,要執行的委托調用。

     4、applicationWillEnterForeground:在應用程序將要進入前臺時(被激活),要執行的委托調用,剛好與applicationWillResignActive 方法相對應。

     5、applicationDidBecomeActive:在應用程序已被激活后,要執行的委托調用,剛好與applicationDidEnterBackground 方法相對應。

     6、applicationWillTerminate:在應用程序要完全推出的時候,要執行的委托調用,這個需要要設置UIApplicationExitsOnSuspend的鍵值。 

     

初次啟動:

2013-05-24 20:20:31.550 LifeIOS[451:c07] iOS_didFinishLaunchingWithOptions

2013-05-24 20:20:31.551 LifeIOS[451:c07] iOS_applicationDidBecomeActive

按下home鍵:

2013-05-24 20:22:17.349 LifeIOS[451:c07] iOS_applicationWillResignActive

2013-05-24 20:22:17.350 LifeIOS[451:c07] iOS_applicationDidEnterBackground

點擊程序圖標進入:

2013-05-24 20:22:56.913 LifeIOS[451:c07] iOS_applicationWillEnterForeground

2013-05-24 20:22:56.914 LifeIOS[451:c07] iOS_applicationDidBecomeActive


程序中沒有設置UIApplicationExitsOnSuspend的值,程序不會徹底退出。


     看上面iOS的生命周期,是不是和Android的Activity生周期也相似,所以說程序是相通的,對比著學習也是收獲最大的。


/**
* @author 張興業
*  http://blog.csdn.net/xyz_lmn
*  iOS入門群:83702688
*  android開發進階群:241395671
*  我的新浪微博:@張興業TBOW
*/

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

哈尔滨市| 东乌珠穆沁旗| 太谷县| 扎赉特旗| 桃源县| 寿光市| 青川县| 德兴市| 虹口区| 加查县| 浙江省| 花莲县| 霍山县| 旬阳县| 晋城| 济南市| 沾益县| 定州市| 义马市| 牟定县| 海阳市| 睢宁县| 章丘市| 临清市| 缙云县| 信丰县| 柘荣县| 岱山县| 舒兰市| 尚义县| 泽普县| 津市市| 汉沽区| 呈贡县| 乌兰察布市| 沂水县| 静海县| 沙洋县| 丘北县| 新蔡县| 兴和县|