1

我调用 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];
}    
}
4

1 回答 1

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];
}
.....

而且您还需要检查您的应用是否在 AppName-info.plist 中有 facebook 的 Url Types 部分

于 2013-05-24T08:49:17.087 回答