//今天遇到了一個(gè)問題
//applicationWillTerminate:(UIApplication *)application 在退出程序時(shí)不執(zhí)行怎么辦?
//答案:直接上代碼...
-
(void)applicationDidEnterBackground:(UIApplication *)application {
NSLog(@"%s", PRETTY_FUNCTION);
__block UIBackgroundTaskIdentifier identifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
if (identifier != UIBackgroundTaskInvalid) {
[[UIApplication sharedApplication] endBackgroundTask:identifier];
identifier = UIBackgroundTaskInvalid;
}
}];dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"執(zhí)行進(jìn)入后臺(tái)調(diào)用的方法...");//此處寫正常進(jìn)入后臺(tái)時(shí)程序需要執(zhí)行的動(dòng)作 if (identifier != UIBackgroundTaskInvalid) { [[UIApplication sharedApplication] endBackgroundTask:identifier]; identifier = UIBackgroundTaskInvalid; }
});
} (void)applicationWillTerminate:(UIApplication *)application {
//此方法內(nèi)寫程序?qū)⒁顺鰰r(shí)需要執(zhí)行的動(dòng)作
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
NSLog(@"%s", __PRETTY_FUNCTION__);
[self.backView removeFromSuperview];
[self.manager closeSocketServer];
[self.conn stopNotifier];
[[NSNotificationCenter defaultCenter]removeObserver:self];
}