Facebook iOS SDK在授权应用程序时不调用完成处理程序

Nat*_*non 1 sdk facebook objective-c ios

我打电话给doFacebookLogin我的应用程序切换到Facebook来授权应用程序但我允许应用程序访问我的信息并切换回来.

什么都没发生.控制台中没有"完整".

如果我再次调用doFacebookLogin,控制台会显示

complete
Session state closed
Run Code Online (Sandbox Code Playgroud)

这是我的代码.

- (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];
}    
}
Run Code Online (Sandbox Code Playgroud)

ner*_*lfe 8

你在AppDelegate有吗?

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication
     annotation:(id)annotation {
// attempt to extract a token from the url

if ([[url scheme] hasPrefix:@"fb"]) {
    return [FBSession.activeSession handleOpenURL:url];
}
.....
Run Code Online (Sandbox Code Playgroud)

此外,您还需要在AppName-info.plist中检查您的应用是否具有适用于Facebook的网址类型部分