简体   繁体   English

初始FBSession检查始终失败

[英]Initial FBSession check consistently fails

I have an app in which the user may choose to login to FB. 我有一个应用程序,用户可以选择登录到FB。 My code is based largely on the tutorials at FB, and for the most part, the app, and the FB integration works as expected. 我的代码主要基于FB的教程,大多数情况下,应用程序和FB集成按预期工作。 The problem I am having is that the app is not remembering from launch to launch that the user has selected to connect the app to FB. 我遇到的问题是应用程序没有记住从启动到启动用户已选择将应用程序连接到FB。 I put a check into AppDelegate.m to check for a cached FBSession: 我检查AppDelegate.m以检查缓存的FBSession:

   if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
        // Yes, so just open the session (this won't display any UX).
        NSLog(@"The state is IS 'State created token loaded'");
        [self openSessionWithAllowLoginUI:NO];
    } else {
        // No, display the login page.
        NSLog(@"The state is NOT 'State created token loaded'");
        [self openSessionWithAllowLoginUI:YES];
    }

Every time I launch the app, the line "The state is NOT 'State created token loaded'" is displayed in the console. 每次启动应用程序时,控制台中都会显示“状态为非'状态创建令牌已加载'”行。 This makes me think I am not doing something right in order to make that FB login persist from launch to launch. 这让我觉得我没有做正确的事情,以使FB登录从发布到发布持续存在。

I could really use some advice here. 我真的可以在这里使用一些建议。 What does one need to do to ensure that "FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded" is true on app launch? 在应用程序启动时,确保“FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded”为真,需要做什么?

If you have this code right when the app starts, then note that: 如果您在应用启动时拥有此代码,请注意:

FBSession.activeSession FBSession.activeSession

May not be set yet. 可能还没有设定。 What you want to do to check for a cached token is something like: 您要检查缓存令牌的目的是:

if (![self openSessionWithAllowLoginUI:NO]) {
    [self openSessionWithAllowLoginUI:YES];
}

The first call with the "NO" will return synchronously with a value of true if there was aa cached token. 如果存在缓存的令牌,则使用“NO”的第一个调用将同步返回值true。 It returns no if there is no cached token. 如果没有缓存的令牌,则返回no。 At this point you can force the login UX to happen. 此时,您可以强制登录UX发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM