I need to save my NSUserDefault
when my app is completely quit in iOS.
not didenterbackground
and foreground
.
Only when user kill my app with minus(-) sign in iOS.
So i write following codes in applicationWillTerminate
of AppDelegate
.
- (void)applicationWillTerminate:(UIApplication *)application
{
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"iCloud"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
But it doesn't save to NSUserDefault
.
So where should i write to save my data?
From Apple Doc :
For apps that do not support background execution or are linked against iOS 3.x or earlier, this method is always called when the user quits the app. For apps that support background execution, this method is generally not called when the user quits the app because the app simply moves to the background in that case. However, this method may be called in situations where the app is running in the background (not suspended) and the system needs to terminate it for some reason.
It's not necessary that applicationWillTerminate
will be called when app exits, it may not be called when your app supports background execution.
You can use UIApplicationExitsOnSuspend to specifies that the app should be terminated rather than moved to the background when it is quit.
I afraid, there isn't any delegate method which will surly handle app's force-quite scenario.
Hope this may help you in solving your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With