In the appdelegate.
applicationWillTerminate
is when the processing application will terminate
By the way, we're going to be doing this in this place when our App is closed.
但是,我发现 App 关闭的时候,并不会走到这里来。
Then I looked at the comments for the system:当应用程序即将终止时调用。如果适当的保存数据。可看 appropriate. See also applicationDidEnterBackground:. 这个方法
It seems to have nothing to do with the problem I'm having! I just want to call when the APP is closed
// 应用程序将终止- (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. NSLog(@"applicationWillTerminate");}
好了,答案来了。
We go to Applicationdidenterbackground to execute a method with the following code:
// 我们到 applicationDidEnterBackground 执行下 beginBackgroundTaskWithExpirationHandler- (void)applicationDidEnterBackground:(UIApplication *)application { // 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. [[UIApplication sharedApplication]beginBackgroundTaskWithExpirationHandler:^(){ }]; NSLog(@"applicationDidEnterBackground");}// 这时候你就会发现 applicationWillTerminate 这货被调用了,有没有人过来解释下。。- (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. NSLog(@"applicationWillTerminate");}
How to monitor when apps are turned off-IOS