最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

老生常談iOS應(yīng)用程序生命周期

 更新時間:2017年04月23日 09:30:13   投稿:jingxian  
下面小編就為大家?guī)硪黄仙U刬OS應(yīng)用程序生命周期。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

開發(fā)應(yīng)用程序都要了解其生命周期。

今天我們接觸一下iOS應(yīng)用程序的生命周期, iOS的入口在main.m文件:

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

main函數(shù)的兩個參數(shù),iOS中沒有用到,包括這兩個參數(shù)是為了與標(biāo)準(zhǔn)ANSI C保持一致。UIApplicationMain函數(shù),前兩個和main函數(shù)一樣,重點是后兩個,官方說明是這樣的:

// 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 * __nullable principalClassName, NSString * __nullable delegateClassName); 

如果主要類(principal class)為nil,將從Info.plist中獲取,如果Info.plist中不存在對應(yīng)的key,則默認(rèn)為UIApplication;如果代理類(delegate class)將在新建工程時創(chuàng)建。

根據(jù)UIApplicationMain函數(shù),程序?qū)⑦M(jìn)入AppDelegate.m,這個文件是xcode新建工程時自動生成的。

應(yīng)用程序的生命周期(AppDelegate.m):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
  // Override point for customization after application launch. 
  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:當(dāng)應(yīng)用程序啟動時執(zhí)行,應(yīng)用程序啟動入口,只在應(yīng)用程序啟動時執(zhí)行一次。若用戶直接啟動,lauchOptions內(nèi)無數(shù)據(jù),若通過其他方式啟動,lauchOptions包含對應(yīng)方式的內(nèi)容。

2、applicationWillResignActive:在應(yīng)用程序?qū)⒁苫顒訝顟B(tài)切換到非活動狀態(tài)時候,要執(zhí)行的委托調(diào)用,如 按下 home 按鈕,返回主屏幕,或全屏之間切換應(yīng)用程序等。

3、applicationDidEnterBackground:在應(yīng)用程序已進(jìn)入后臺程序時,要執(zhí)行的委托調(diào)用。

4、applicationWillEnterForeground:在應(yīng)用程序?qū)⒁M(jìn)入前臺時(被激活),要執(zhí)行的委托調(diào)用,剛好與applicationWillResignActive 方法相對應(yīng)。

5、applicationDidBecomeActive:在應(yīng)用程序已被激活后,要執(zhí)行的委托調(diào)用,剛好與applicationDidEnterBackground 方法相對應(yīng)。

6、applicationWillTerminate:在應(yīng)用程序要完全推出的時候,要執(zhí)行的委托調(diào)用,這個需要要設(shè)置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

點擊程序圖標(biāo)進(jìn)入:

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

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

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

以上這篇老生常談iOS應(yīng)用程序生命周期就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • iOS使用核心動畫和粒子發(fā)射器實現(xiàn)點贊按鈕的方法

    iOS使用核心動畫和粒子發(fā)射器實現(xiàn)點贊按鈕的方法

    這篇文章主要給大家介紹了iOS如何使用核心動畫和粒子發(fā)射器實現(xiàn)點贊按鈕的方法,文中給出了詳細(xì)的示例代碼,相信對大家的理解和學(xué)習(xí)具有一定的參考借鑒,有需要的朋友們下面跟著小編一起來學(xué)習(xí)學(xué)習(xí)吧。
    2016-12-12
  • iOS實現(xiàn)抽屜效果

    iOS實現(xiàn)抽屜效果

    這篇文章主要為大家詳細(xì)介紹了iOS實現(xiàn)抽屜效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-02-02
  • iOS實現(xiàn)第三方微信登錄方式實例解析(最新最全)

    iOS實現(xiàn)第三方微信登錄方式實例解析(最新最全)

    這篇文章主要介紹了iOS實現(xiàn)第三方微信登錄方式實例解析(最新最全),非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-12-12
  • iOS開發(fā)tips-UINavigationBar的切換效果

    iOS開發(fā)tips-UINavigationBar的切換效果

    這篇文章主要為大家詳細(xì)介紹了iOS開發(fā)tips-UINavigationBar的切換效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • iOS實現(xiàn)計算器小功能

    iOS實現(xiàn)計算器小功能

    這篇文章主要介紹了iOS實現(xiàn)計算器小功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • iOS開發(fā)之UIKeyboardTypeNumberPad數(shù)字鍵盤自定義按鍵

    iOS開發(fā)之UIKeyboardTypeNumberPad數(shù)字鍵盤自定義按鍵

    這篇文章主要介紹了iOS開發(fā)之UIKeyboardTypeNumberPad數(shù)字鍵盤自定義按鍵 的相關(guān)資料,需要的朋友可以參考下
    2016-08-08
  • iOS CAReplicatorLayer實現(xiàn)脈沖動畫效果

    iOS CAReplicatorLayer實現(xiàn)脈沖動畫效果

    這篇文章主要介紹了iOS CAReplicatorLayer實現(xiàn)脈沖動畫效果 ,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • 源碼解析ios開發(fā)SDWebImage方法

    源碼解析ios開發(fā)SDWebImage方法

    這篇文章主要為大家介紹了源碼解析ios開發(fā)SDWebImage方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08
  • IOS實現(xiàn)視頻動畫效果的啟動圖

    IOS實現(xiàn)視頻動畫效果的啟動圖

    這篇文章實現(xiàn)的是一個關(guān)于啟動頁或者引導(dǎo)頁的視頻動畫效果的實現(xiàn)過程,對于大家開發(fā)APP具有一定的參考借鑒價值,有需要的可以來看看。
    2016-09-09
  • iOS仿微信搖一搖功能

    iOS仿微信搖一搖功能

    這篇文章主要為大家詳細(xì)介紹了iOS仿微信搖一搖功能的實現(xiàn)方法 ,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05

最新評論

武宣县| 灵山县| 奉节县| 蒲城县| 贵定县| 张北县| 闸北区| 广昌县| 绍兴市| 八宿县| 江孜县| 阿克苏市| 陕西省| 宜君县| 讷河市| 阿合奇县| 启东市| 汉寿县| 云梦县| 公主岭市| 邯郸县| 隆德县| 枣阳市| 茶陵县| 中牟县| 永济市| 大化| 定边县| 阳朔县| 长葛市| 乐都县| 井冈山市| 正定县| 肥东县| 华坪县| 鄂托克旗| 上杭县| 永川市| 海伦市| 新田县| 丹巴县|