I need to save my NSUserDefault
when my app is completely quit in iOS.
not didenterbackground
and foreground
.
Only when user kill my app w
The problem is that applicationWillTerminate
is not getting called at all.
Change your applicationDidEnterBackground
as below and kill your application within 20 seconds.
You can see applicationWillTerminate
getting called & setting your iCloud
value properly in NSUserDefaults
- (void)applicationDidEnterBackground:(UIApplication *)application
{
__block UIBackgroundTaskIdentifier identifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
if (identifier != UIBackgroundTaskInvalid) {
[[UIApplication sharedApplication] endBackgroundTask:identifier];
identifier = UIBackgroundTaskInvalid;
}
}];
dispatch_async(dispatch_get_main_queue(), ^{
for (int i=0; i < 20; i++) {
NSLog(@"%d", i);
sleep(1);
}
if (identifier != UIBackgroundTaskInvalid) {
[[UIApplication sharedApplication] endBackgroundTask:identifier];
identifier = UIBackgroundTaskInvalid;
}
});
}