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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With