facebook SDK [Firebase Ref.,Swift] 中缺少 FBSessionStateOpen

Posted

技术标签:

【中文标题】facebook SDK [Firebase Ref.,Swift] 中缺少 FBSessionStateOpen【英文标题】:Missing FBSessionStateOpen from facebook SDK [Firebase Ref.,Swift] 【发布时间】:2014-12-29 16:11:41 【问题描述】:

我正在尝试连接 firebase 和 facebook 作为参考 https://www.firebase.com/docs/ios/guide/login/facebook.html#section-authenticating

FacebookSDK 3.21.1 版本

这是我遇到的问题

state.value == FBSessionStateOpen.value 

FBSessionStateOpen 是未解析的标识符

我已经创建了包含

的桥头
#import <FacebookSDK/FacebookSDK.h> 

我在 FacebookSDK.framework 中已经看到 FBSession.h 中已经包含 FBSessionStateOpen

typedef NS_ENUM(NSUInteger, FBSessionState) 
    ...
    /*! Open session state indicating user has logged in or a cached token is available */
    FBSessionStateOpen                      = 1 | FB_SESSIONSTATEOPENBIT,
    ...
;

完整代码来自 firebase

let ref = Firebase(url: "https://<YOUR-FIREBASE>.firebaseio.com")
FBSession.openActiveSessionWithReadPermissions(["public_profile"], allowLoginUI: true,
     completionHandler:  session, state, error in

    if error != nil 
        println("Facebook login failed. Error \(error)")
     else if state.value == FBSessionStateOpen.value 
        let accessToken = session.accessTokenData.accessToken
        ref.authWithOAuthProvider("facebook", token: accessToken,
            withCompletionBlock:  error, authData in

            if error != nil 
                println("Login failed. \(error)")
             else 
                println("Logged in! \(authData)")
            
        )
    

【问题讨论】:

为什么这个漂亮的问题被降级了?我也有类似的问题。 【参考方案1】:

我已经尝试将语句更改为并且它有效!

来自

state.value == FBSessionStateOpen.value 

state.hashValue == FBSessionState.Open.hashValue

虽然我不确定它是否应该是这样的。

【讨论】:

【参考方案2】:

试试这个

func login(callback: () -> Void)

        let permission = ["email","user_location","user_birthday","user_hometown","user_photos","user_about_me"];

        let activeSession = FBSession.activeSession();
        let fbsessionState = activeSession.state;
        var showLoginUI = true;

        if(fbsessionState == FBSessionState.CreatedTokenLoaded)
            showLoginUI = false;
        

        if(fbsessionState != FBSessionState.Open
            && fbsessionState != FBSessionState.OpenTokenExtended)
                FBSession.openActiveSessionWithReadPermissions(
                    permission,
                    allowLoginUI: showLoginUI,
                    completionHandler:  (session:FBSession!, state:FBSessionState, error:NSError!) in

                        if(error != nil)
                            println("Session Error: \(error)");
                        

                        self.fbSession = session;

                        callback();

                    
                );
                return;
        

        callback();

    

【讨论】:

以上是关于facebook SDK [Firebase Ref.,Swift] 中缺少 FBSessionStateOpen的主要内容,如果未能解决你的问题,请参考以下文章

facebook SDK [Firebase Ref.,Swift] 中缺少 FBSessionStateOpen

添加 Facebook sdk 和 Google Firebase sdk 时的 Android Proguard 问题(重复)

如何使用 Firebase 统一创建 Facebook 登录?

Firebase Facebook 登录 - 检测用户登录状态并重定向

为啥 Facebook 身份验证 SDK 在不同模式下的表现如此不同?

正确使用Firebase身份验证?