Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FaceBook SDK3.5 closeAndClearTokenInformation calls completion handler of openActiveSessionWithReadPermissions

I have the following code that I use during facebook login.

- (BOOL)openFBSessionWithAllowLoginUI:(BOOL)allowLoginUI
            withCompletionHandler:(void (^)())completionHandler
{

    NSArray *permissions = [NSArray arrayWithObjects:
                        @"user_photos",
                        @"email",
                        nil];
    return [FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:allowLoginUI completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
       if (error != nil) {
        ...
       } else {
            switch (state) {
               case FBSessionStateOpen:
               {
                   ...
               }
               case FBSessionStateClosed:
               {
                   ...
               }
               case FBSessionStateClosedLoginFailed:
               {
                   ...
               }
               default:
                   break;
           }
       }
   }];
}

The above works fine for login. But, when I log out using the following code

[FBSession.activeSession closeAndClearTokenInformation];

this again calls the completionHandler of openActiveSessionWithReadPermissions:permissions allowLoginUI:. That does not make sense to me. I do not think it is the right behavior. Has anyone seen this problem? How do we log-out? I am using SDK 3.5 on iOS6.

like image 282
Shirish Kumar Avatar asked May 24 '13 22:05

Shirish Kumar


1 Answers

According to this thread on the Facebook Developer bug tracker, this behavior is "by design".

In fact, I did suggest a better name for this method would be: openActiveSessionWithReadPermissions:allowLoginUI:stateChangeHandler:

as that more accurately describes what's happening (the "completionHandler" is in fact called on state change).

You can handle this in several ways: Ben Cohen suggest you can either set the completionHandler to nil within the completion block (to ensure run-once), this answer suggests creating an FBSessionStateHandler run-once handler, or you can switch on the state change.

Ideally, as we rely on the Facebook SDK for specific purposes (log in, log out, make requests, etc.), these would be provided via delegates, but since the SDK developers apparently got a bit carried away with "ooh blocks!!", you're left having to define your state change handler at the point where you first open your session.

like image 179
cleverbit Avatar answered Oct 12 '22 19:10

cleverbit