So I am using the NSUserDefaults to store my FBAccessTokenKey and FBExpirationDateKey. I am creating a singleton User object:
- (id)init
{
self = [super init];
if (self != nil) {
facebook = [[Facebook alloc] initWithAppId:kAppId andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"] ) {
NSLog(@"ACCESS KEY IS NOT EMPTY");
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
} else {
NSLog(@"ACCESS KEY IS EMPTY");
}
}
return self;
}
I also have implemented a didLogout method that is called when I logout:
- (void)fbDidLogout {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"FBAccessTokenKey"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"FBExpirationDateKey"];
}
This basically clears/flushes out the token key.
Now the real issue is that when I click on logout, quit the app, and then run the app again, it detects that the key FBAccessTokenKey and FBExpirationDateKey is still there. Why is this?
you should call:
[[NSUserDefaults standardUserDefaults] synchronize]before exit