通过添加通知:
//1、添加进入后台的判断
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(comeHome:) name:@"UIApplicationDidEnterBackgroundNotification" object:nil];
- (void)comeHome:(UIApplication *)application {
NSLog(@"进入后台");
}
//2、添加程序被杀死的判断
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:@"UIApplicationWillTerminateNotification" object:nil];
- (void)applicationWillTerminate:(UIApplication *)application {
NSLog(@"程序被杀死");
}
网友评论