G.P.Reddy G.P.Reddy - 3 months ago 20
Objective-C Question

Removed NSUserDefaults

here i can use

NSUserDefaults
,but i need to
remove
this
NSUserDefaults
. In my app I'm using
NSUserDefaults
for getting locations one
View
to
anotherView
but here issue when I'm closed to the my app ,and again i started still the locations are there ,here i used for removing locations in
AppDeligate


- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[NSUserDefaults standardUserDefaults]removeObjectForKey:@"Location"];
}


But still locations is there.how can i removed this?
Can you suggest me.

Answer

change your method

- (void)applicationDidEnterBackground:(UIApplication *)application
{
 [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"Location"];
 [[NSUserDefaults standardUserDefaults] synchronize];

}

into

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


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

}

whenever you remove or add values in NSUserDefaults don't forget to call [[NSUserDefaults standardUserDefaults] synchronize];, if your fetching the values on that time no need to add [[NSUserDefaults standardUserDefaults] synchronize];