Code cracker Code cracker - 3 months ago 10
Objective-C Question

iOS app is closed from background

I made an iOS app, in that am using

NSUserDefaults
.If app is closed from the background I want to remove the strings which are stored in
NSUserDefaults
.Can anyone give me the solutions for find the app is closed from background.

Answer

u can clear your NSUserDefaults in 2 ways, one applicationWillTerminate another one didFinishLaunchingWithOptions is called at initial time only

// if u terminated your application surly it remove the all keys and other local DB 

- (void)applicationWillTerminate:(UIApplication *)application
{


 [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"addyourkeys"]; 
 [[NSUserDefaults standardUserDefaults] synchronize];

 }

choice No :2

   // it is called only initially time , u can also follow your work at here.. but no need at here the applicationWillTerminate will follow the work 

- (void)applicationDidFinishLaunching:(UIApplication *)application
{


 [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"addyourkeys"]; 
 [[NSUserDefaults standardUserDefaults] synchronize];

 }