0

我有一个集成了 Facebook 登录的原生 iOS 应用程序。安装本机 Facebook 应用程序时,登录流程有效。

但是,当我删除该应用程序时,FB Mobile Safari webapp 上的 FB 登录回退。应用程序切换工作正常,但是当控件返回到我的应用程序时,会话状态被声明为 FBSessionStateClosedLoginFailed。

截至 2013 年 6 月 6 日,我正在使用 Facebook SDK v3.5.2 使用 iPad1 iOS5.1.1

    /*
     * Opens a Facebook session and optionally shows the login UX.
     */
    - (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
        NSArray *permissions = [[NSArray alloc] initWithObjects:
                                @"email",
                    @"publish_actions",
                                nil];
        BOOL result = NO;
        FBSession *session =
        [[FBSession alloc] initWithAppID:nil
                             permissions:permissions
                         urlSchemeSuffix:@"<MySchemeSuffix>"
                      tokenCacheStrategy:nil];


        if (allowLoginUI ||
            (session.state == FBSessionStateCreatedTokenLoaded)) {
            [FBSession setActiveSession:session];
            [session openWithBehavior:FBSessionLoginBehaviorWithFallbackToWebView
                    completionHandler:
             ^(FBSession *session, FBSessionState state, NSError *error)
             {
                 [self sessionStateChanged:session state:state error:error];
             }];
            result = session.isOpen;
        }

        return result;
    }

    /*
     * If we have a valid session at the time of openURL call, we handle
     * Facebook transitions by passing the url argument to handleOpenURL
     */
    - (BOOL)application:(UIApplication *)application
                openURL:(NSURL *)url
      sourceApplication:(NSString *)sourceApplication
             annotation:(id)annotation {
    // attempt to extract a token from the url
        //return [FBSession.activeSession handleOpenURL:url];
        BOOL urlWasHandled = [FBAppCall handleOpenURL:url
                                    sourceApplication:sourceApplication
                                      fallbackHandler:^(FBAppCall *call) {
                                          // handle deep links and responses for Login or Share Dialog here
                                      }];

        return urlWasHandled;
    }

    /*
 * Callback for session changes.
 */
- (void)sessionStateChanged:(FBSession *)session
                      state:(FBSessionState) state
                      error:(NSError *)error
{
    switch (state) {
        case FBSessionStateOpen:
            if (!error) {
                if (FBSession.activeSession.isOpen) {
                    [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
                        //Application specific code goes here.
                        }
                    }];
                }
                // We have a valid session
                NSLog(@"User session found");
            }
            break;
        case FBSessionStateClosed:
        case FBSessionStateClosedLoginFailed:
            [FBSession.activeSession closeAndClearTokenInformation];
            break;
        default:
            break;
    }
}
4

1 回答 1

0

我碰巧解决了这个问题。

错误是,我在同一个调用中请求读取和写入权限。从权限中取出“publish_actions”解决了这个问题。

我通过原生 FB 登录、原生 FB 应用和 webapp 在 iOS6+ 中测试了 Facebook 登录。还在 iOS5.1.1 上通过原生 FB 应用和 webapp 进行了测试。

于 2013-06-12T19:18:31.557 回答