国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

應用程序掛起、復原與終止— IOS開發

2019-11-09 17:45:27
字體:
來源:轉載
供稿:網友

一、掛起

當有電話進來或者鎖屏,這時你的應用程會掛起,在這時,UIapplicationDelegate委托會收到通知,調用 applicationWillResignActive 方法,你可以重寫這個方法,做掛起前的工作,比如關閉網絡,保存數據。

C代碼  收藏代碼- (void)applicationWillResignActive:(UIApplication*)application{    /*添加你自己的掛起前準備代碼*/    }     

當你的程序被掛起后他不會在后臺運行。

 

二、復原

當程序復原時,另一個名為 applicationDidBecomeActive 委托方法會被調用,在此你可以通過之前掛起前保存的數據來恢復你的應用程序:

C代碼  收藏代碼- (void)applicationDidBecomeActive:(UIApplication*)application{    /*添加你的恢復代碼*/    }     

注意:應用程序在啟動時,在調用了 applicationDidFinishLaunching 方法之后也會調用 applicationDidBecomeActive 方法,所以你要確保你的代碼能夠分清復原與啟動,避免出現邏輯上的bug。

 

三、終止

當用戶按下按鈕,或者關機,程序都會被終止。當一個程序將要正常終止時會調用 applicationWillTerminate 方法。但是如果長主按鈕強制退出,則不會調用該方法。這個方法該執行剩下的清理工作,比如所有的連接都能正常關閉,并在程序退出前執行任何其他的必要的工作:

C代碼  收藏代碼- (void)applicationWillTerminate:(UIApplication*)application{    /*在這里添加退出前的清理代碼以及其他工作代碼*/    }     

來源: http://blog.csdn.net/iukey/article/details/7311115

 

 

java代碼  收藏代碼- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  {      // Override point for customization after application launch.      NSLog(@"/n ===> 程序開始 !");             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(@"/n ===> 程序暫行 !");   }    - (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(@"/n ===> 程序進入后臺 !");   }    - (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(@"/n ===> 程序進入前臺 !");   }    - (void)applicationDidBecomeActive:(UIApplication *)application  {      NSLog(@"/n ===> 程序重新激活 !");       /*      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.      */  }    - (void)applicationWillTerminate:(UIApplication *)application  {      NSLog(@"/n ===> 程序意外暫行 !");         UIDevice *device = [UIDevice currentDevice];      /*      Called when the application is about to terminate.      Save data if appropriate.      See also applicationDidEnterBackground:.      */  }   

首次運行:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

- (void)applicationDidBecomeActive:(UIApplication *)application

 

首次關閉(home):

- (void)applicationWillResignActive:(UIApplication *)application

- (void)applicationDidEnterBackground:(UIApplication *)application

 

再次運行:

- (void)applicationWillEnterForeground:(UIApplication *)application

- (void)applicationDidBecomeActive:(UIApplication *)application

 

再次關閉:

- (void)applicationWillResignActive:(UIApplication *)application

- (void)applicationDidEnterBackground:(UIApplication *)application


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 霍邱县| 根河市| 伊春市| 阿城市| 新绛县| 静乐县| 高要市| 桐柏县| 海伦市| 射洪县| 克山县| 湘潭市| 西吉县| 齐齐哈尔市| 阿尔山市| 奉化市| 绍兴市| 手游| 广南县| 云梦县| 龙海市| 应用必备| 安阳县| 调兵山市| 洛阳市| 明溪县| 昭通市| 贵州省| 碌曲县| 肇源县| 宁晋县| 临海市| 阳曲县| 武强县| 曲水县| 宜都市| 蓝田县| 霍林郭勒市| 轮台县| 定襄县| 怀宁县|