0

I'm working on a project with multiple people. the app is set up to log a user in via facebook. There was a bug submitted saying that if you log out of facebook, it immediately logs you back in. Not every time, but frequently. After checking into it, i discovered that when you start the app and log out for the first time, it does in fact log you right back in immediately afterward. This was the code that logged the user out:

[FBSession.activeSession closeAndClearTokenInformation];

[[NSUserDefaults standardUserDefaults] removeObjectForKey:kHOUserDefaults];
[[NSUserDefaults standardUserDefaults] synchronize];

[[NSNotificationCenter defaultCenter] postNotificationName:kHOuserDefaultsWasRemoved
                                                    object:nil];

After editing the source code to try to fix the problem, this is what the code looked like:

[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
[FBSession setActiveSession:nil];

[[NSUserDefaults standardUserDefaults] removeObjectForKey:kHOUserDefaults];
[[NSUserDefaults standardUserDefaults] synchronize];

[[NSNotificationCenter defaultCenter] postNotificationName:kHOuserDefaultsWasRemoved
                                                    object:nil];

Now that the code looks like that, it doesn't log you in immediately after logout like before. It does, however, require two clicks on the FBLoginView. If it's at the point where it would have normally logged you back in, it only requires 1 touch. The class is set up as a delegate to the facebook API. here's what the class that handles the touch events looks like (includes < FBLoginViewDelegate >):

-(void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user{
    self.userAuthentication.user = user;
    self.userAuthentication.accessToken = [[[FBSession activeSession] accessTokenData] accessToken];
    [SVProgressHUD showWithStatus:@"Logging in"];
    [self.userAuthentication authenticatedUserFromFacebook:^(NSString *aString, NSNumber *aNumber, id aResult) {
            [SVProgressHUD showSuccessWithStatus:aString];
    }];
}

any ideas why it would be doing that? what could be causing the problem? i'm very confused by this issue.

1 Answer 1

2

Not sure you solved this already, but I just fixed that same problem.

It has to do with the way you log out. Use this snippet:

[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
[FBSession setActiveSession:[[FBSession alloc] init]];

This way, you clear the active session but you create a new one already, which is what I believe the first tap was doing.

Not the answer you're looking for? Browse other questions tagged or ask your own question.