//今天遇到了一個問題
//applicationWillTerminate:(UIApplication *)application 在退出程序時不執行怎么辦?
//答案:直接上代碼...
-
(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(@"執行進入后臺調用的方法...");//此處寫正常進入后臺時程序需要執行的動作 if (identifier != UIBackgroundTaskInvalid) { [[UIApplication sharedApplication] endBackgroundTask:identifier]; identifier = UIBackgroundTaskInvalid; }
});
} (void)applicationWillTerminate:(UIApplication *)application {
//此方法內寫程序將要退出時需要執行的動作
// 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];
}