我的需求是,app推入后台,不做用户信息清除,但是程序被用户双击上滑杀死后,就对app用户信息做一个清除,让用户再次打开app时重新登录,so,就要获取app被杀死的事件了,appDelegate里面的applicationWillTerminate函数不会走,原因我也不知道,但是通过下面的方式是可以实现该需求的,求大神指教破解原理:
- (void)applicationDidEnterBackground:(UIApplication *)application {
//实现一个可以后台运行几分钟的权限, 当用户在后台强制退出程序时就会走applicationWillTerminate 了.
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil];
// 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.
}
- (void)applicationWillTerminate:(UIApplication *)application {
// NSLog(@"程序被杀死");
[[NSUserDefaults standardUserDefaults] setObject:@"N" forKey:@"isLogined"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
复制代码