Swift Facebook 登录 sdk 错误代码 2

Swift Facebook Login sdk error with code 2

我在使用 Facebook 登录时遇到错误。 它在 3-4 个月前就开始工作了

现在我重新开始开发这个应用程序,我将开发目标从 iOS 12.0 更改为 iOS 13.0 并添加了 SceneDelegate 和其他必要的东西。其实,我不认为这是原因,但值得一提。

现在我收到这个错误:

FBSDKLog: Cannot login without a valid login configuration. Please make sure the LoginConfiguration provided is non-nil Error Domain=com.facebook.sdk.core Code=2 "(null)" UserInfo={com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Cannot login without a valid login configuration. Please make sure the LoginConfiguration provided is non-nil}

而 运行 这个:

fbLoginManager.logIn(permissions: ["email, public_profile"], from: self) { (loginResult, error) in
        if error != nil {
            print(error!)
        }
        
        if let currentToken = AccessToken.current {
            let credential = FacebookAuthProvider.credential(withAccessToken: currentToken.tokenString)
            Auth.auth().signIn(with: credential) { (authResult, error) in
                if let error = error {
                    let authError = error as NSError
                    print(authError)
                } else {
                    DispatchQueue.main.async {
                        self.setupTabbar()
                        self.dismiss(animated: true, completion: nil)
                    }
                }
            }
        }
    }

我检查了 info.plist 几次并从头开始应用说明,但我仍然收到此错误。

我正在使用 XCode 12.5 和 Swift 5

编辑:当我删除权限时它有效但我实际上需要这些权限。

解决方案

我将权限从 ["email, public_profile"] 更改为: ["email", "public_profile"]

看起来像这样:

fbLoginManager.logIn(permissions: ["email", "public_profile"], from: self) { (loginResult, error) in
        if error != nil {
            print(error!)
        }
        
        if let currentToken = AccessToken.current {
            let credential = FacebookAuthProvider.credential(withAccessToken: currentToken.tokenString)
            Auth.auth().signIn(with: credential) { (authResult, error) in
                if let error = error as NSError? {
                    print(error)
                } else {
                    DispatchQueue.main.async {
                        self.setupTabbar()
                        self.dismiss(animated: true, completion: nil)
                    }
                }
            }
        }
    }