Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

facebook ios sdk 3.1.1 FBSession completionHandler not removed

Tags:

ios

facebook

When I open the Facebook session everything goes fine and the completion block gets called.

[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:allowLoginUI 
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
                                             NSLog(@"openSession handler");
                                     }];

But later when I ask for extra permissions for example, both completion blocks get called not only the new one.

    [FBSession.activeSession reauthorizeWithReadPermissions:
    [NSArray arrayWithObject:@"user_photos"] 
completionHandler:^(FBSession *session, NSError *error) {
                    NSLog(@"reauthorize handler");
                }];

Is this a bug or is it supposed to be like this? How can I avoid this behaviour? Is it possible to delete the completion block after the call?

I looked into the Scrumptious sample and the behaviour is exactly the same. When the app asks for publish permissions the publish-completion block gets called and the login block gets called again.

I'm testing on iOS5 and Facebook-ios-sdk 3.1.1

like image 323
user1723724 Avatar asked Oct 05 '12 18:10

user1723724


1 Answers

From what I could gather from Facebook's documentation in the API, this is an intended behaviour (not good design IMHO but that's another story).

Snippet in the description of the completionHandler param:

"...the FBSession object will call the block each time the session changes state"

I can't offer you a fix, but I can offer a workaround:

// <Your description of why the workaround is needed.
//
// REF: http://stackoverflow.com/questions/12751635/facebook-ios-sdk-3-1-1-fbsession-completionhandler-not-removed
//
__block BOOL workaroundOneTimeRunFlag = NO;

[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:allowLoginUI completionHandler:^(FBSession *session, FBSessionState state, NSError *error)
{
    if (!workaroundOneTimeRunFlag)
    {
        workaroundOneTimeRunFlag = YES;

        // Your handler was executed for the first time
        // Run some code...
    }
}];
like image 196
diegoreymendez Avatar answered Sep 28 '22 10:09

diegoreymendez