Facebook 登录显示两次

Facebook Login Showing Twice

Facebook 登录屏幕显示两次,第一个是常规登录页面,但第二个显示 "you have already authorized my app name"。谁能告诉我我的代码做错了什么。

这是我的登录码:

 static func createAndLogin(_ viewController: UIViewController, completion: @escaping (_ success: Bool) -> Void) {
    let loginManager = FBSDKLoginManager()
    loginManager.logOut()
    loginManager.logIn(withReadPermissions: ["public_profile", "email", "user_friends"], from: viewController) { (result, error) -> Void in
        if error != nil {
            print("login FAILED \(error)")
            completion(false)
        } else if (result?.isCancelled)!{
            print("login is CANCELLED")

            completion(false)
        } else if FBSDKAccessToken.current() != nil {

            let accessToken = FBSDKAccessToken.current().tokenString
            let credential = FIRFacebookAuthProvider.credential(withAccessToken: accessToken!)
            FIRAuth.auth()?.signIn(with: credential, completion: { (user, error) in
                if error != nil {
                    print("SIGN IN WITH FIREBASE FAILED")
                    completion(false)
                } else {
                    print("YAY LOGIN SUCCESSFULL!!!!")
                    if let mainUser = FIRAuth.auth()?.currentUser?.providerData{
                        for profile in mainUser {
                            let providerID = profile.providerID
                            let uid = profile.uid // provider-specific UID
                            let name = profile.displayName
                            let email = profile.email
                            let photoUrl = profile.photoURL
                            if (FBSDKAccessToken.current() != nil) {
                                let facebookRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, gender, first_name, last_name, middle_name, picture"])

                                facebookRequest?.start(completionHandler: { (connection, result, error) in

                                    if error == nil {
                                        print(result as Any)
                                        let data = result as! NSDictionary
                                        let gender = data.object(forKey: "gender") as! String

                                        var newUser = User(firstName: name!, profileImageURL: ("\(photoUrl!)"), gender: gender)
                                        newUser.save()
                                        self.currentUserID = uid

                                    }
                                })
                            }
                            completion(true)

                        }

                    }
                }
            })

        }

    }

}

这是默认登录行为所期望的。您可能想尝试设置 loginManager.loginBehavior = .systemAccount 以获得更流畅的登录体验。这将尝试使用您在设置中提供给苹果的 FB 凭据登录,这根本不需要切换应用程序。如果用户未在设置中登录 FB,那么它将退回到其他更具侵入性的方法之一(webivew 或 FB 应用程序)。