0

我正在实施新的 Facebook SDK,除了登录后,一切似乎都井井有条。当应用程序将我带到 Safari 并给它“好的”时,它会返回应用程序并报告成功:

- (void)sessionStateChanged:(FBSession *)session
                      state:(FBSessionState) state
                      error:(NSError *)error
{
    switch (state) {
        case FBSessionStateOpen: {
            NSLog(@"success");
        }

.
.
.

}

但是当我在之后立即检查状态时:

if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
    NSLog(@"Logged in");
} else {
    NSLog(@"Not logged in");
}

我得到:未登录。我没有收到任何错误消息。令牌似乎在发行后立即过期。想要一些关于如何解决这个问题的指导。此应用程序是作为一个新项目创建的,但它是对现有应用程序的更新。但是,运行新应用程序时,旧应用程序不在我的设备上。只是想我会提到它应该很重要。

4

1 回答 1

1

该状态特定于这种情况:

 /*! One of two initial session states indicating that a cached token was loaded;
     when a session is in this state, a call to open* will result in an open session,
     without UX or app-switching*/
    FBSessionStateCreatedTokenLoaded        = 1,

Since the "success" NSLog is executed in the code you posted, your state is actually: FBSessionStateOpen. Which means you are logged in and have a valid access token (log out FBSession.activeSession.accessToken to validate). Anyway, I believe you should be good - your loggedIn/notLoggedIn condition was just invalid.

于 2012-11-17T21:11:21.480 回答