问题
Using the code from Facebook I have implemented
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"publish_actions",
nil];
return [FBSession openActiveSessionWithPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
NSLog(@"error %@", error);
[self sessionStateChanged:session
state:state
error:error];
}];
}
It returns NO which I understand because it's a first time login, and the loginUI works (it sends the user to FB and asks them to give permissions) and then returns but completionHandler block is never ever run. It just returns to the app and nada.
回答1:
I assume you following Implement the Login Flow of Facebook SDK but worth reading that section again as it explains everything. Make sure that you handled openURL and handleOpenURL methods in delegate. Also check openSessionWithAllowLoginUI almost always returns NO
回答2:
Little late, but just in case someone comes checking...
Switching from openActiveSession to the instance method openWithCompletionHandler did the trick for me.
回答3:
from the official doc
handler
... If a block is provided, the FBSession object will call the block each time the session changes state.
I fixed this problem my solving Open Graph setups and by studying Scrumptious example code from FB such as these functions [FBSession.activeSession handleOpenURL:url] and [FBSession.activeSession handleDidBecomeActive];
来源:https://stackoverflow.com/questions/12514740/facebook-sdk-openactivesessionwithpermissions-completionhandler-not-called