我调用 doFacebookLogin 我的应用程序切换到 facebook 以授权该应用程序,但在我允许该应用程序访问我的信息并切换回来之后。
什么都没发生。控制台中没有“完成”。
如果我再次调用 doFacebookLogin 控制台将显示
complete
Session state closed
这是我的代码。
- (void)doFacebookLogin:(id)sender
{
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:
^(FBSession *session,FBSessionState state, NSError *error) {
NSLog(@"complete");
[self sessionStateChanged:session state:state error:error];
}];
}
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState)state error:(NSError *)error
{
NSLog(@"Session state changed");
switch (state) {
case FBSessionStateOpen:
NSLog(@"Session state open");
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if(error == nil) {
NSLog(@"%@", [user debugDescription]);
}
}];
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
NSLog(@"Session state closed");
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
if(error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}