Facebook openActiveSessionWithReadPermission达到完成速度太快,状态失败

时间:2013-01-04 10:04:11

标签: objective-c xcode

[FBSession openActiveSessionWithReadPermissions:nil
                                   allowLoginUI:YES
                              completionHandler:
 ^(FBSession *session,
   FBSessionState state, NSError *error) {
     [self sessionStateChanged:session state:state error:error];
 }];

好吧,过了一会儿警报告诉我们说我的应用程序试图访问facebook并询问是否允许它。

但是,该警报会在达到完成处理程序后显示。

到那时状态已经是FBSessionStateClosedLoginFailed。

我该怎么办?在模拟器中工作正常。

实际上,面部书中的美味样本也在我的iPhone上失败了。但我已经安装并登录了facebook应用程序。

1 个答案:

答案 0 :(得分:1)

Facebook登录清单:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [FBSession.activeSession handleOpenURL:url];
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // We need to properly handle activation of the application with regards to SSO
    //  (e.g., returning from iOS 6.0 authorization dialog or from fast app switching).
    [FBSession.activeSession handleDidBecomeActive];
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // if the app is going away, we close the session object; this is a good idea because
    // things may be hanging off the session, that need releasing (completion block, etc.) and
    // other components in the app may be awaiting close notification in order to do cleanup
    [FBSession.activeSession close];
}

在我的sessionStateChanged中:我正在做这个

switch ( state ) {
    case FBSessionStateOpen:
        [[Facebook _instance] fbDialogLogin:session.accessToken expirationDate:session.expirationDate];
        break;
    case FBSessionStateClosed:
        [FBSession.activeSession closeAndClearTokenInformation];
        break;
    case FBSessionStateClosedLoginFailed:
        break;
    default:
        NSLog(@"FBSessionStateUnknown: %d", state);
        break;
}

并且不要忘记确保您的FacebookAppID和BundleID与您在Facebook Developer Dashboard中创建的相同!