iOS Application will terminate does not work in background

192 views Asked by At

I am trying to set a user default when my application is killed in the background, this code does not work unless the application is open then you background kill it, if the application is closed it does not work. Is there any way around this? I need to make it so that if the application reloads after being killed fully that it will do the following but if put into the background and reloaded it won't do anything.

- (void)applicationWillTerminate:(UIApplication *)application {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:@"KILLED" forKey:@"grabngostoreselected"];
    [userDefaults removeObjectForKey:@"grabngocartid"];
    [userDefaults removeObjectForKey:@"grabngocartq"];
}
1

There are 1 answers

0
AbecedarioPoint On

sometime not NSUserDefaults not synchronize by default so you need to forcefully synchronize NSUserDefaults

[defaults synchronize];

for more information Please refer this

and also please refer for applicationWillTerminate information