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

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

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

到那时,状态已经是 FBSessionStateClosedLoginFailed。

我应该怎么办?在模拟器中运行良好。

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

4

1 回答 1

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 中创建的相同!

于 2013-03-06T05:14:47.590 回答