Reputation: 556
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.
Upvotes: 2
Views: 109
Reputation: 82759
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];
Upvotes: 1