//今天遇到了一个问题
//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];
}