gpt4 book ai didi

ios - 尝试通过 FirebaseUI Auth 连接 Facebook 登录,但遇到 authUI.delegate = self 问题

转载 作者:行者123 更新时间:2023-11-30 13:17:52 24 4
gpt4 key购买 nike

我正在尝试通过 FirebaseUI Auth 连接 Facebook 登录,但是我无法让 Facebook 连接按钮出现在实例化的 authViewController 中。平台:iOS,语言:Swift 2.0,最新稳定的 Xcode 版本

就拉起实例化 authViewController 而言,一切都正常工作。电子邮件/密码选项已存在,并会在我的 Firebase 数据库中主动创建新用户。

我在尝试实现 Facebook 登录功能时遇到的问题;

在我的 AppDelegate.swift 文件中,我有以下内容:

import Firebase
import FirebaseAuthUI
...
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

FIRApp.configure()
let authUI = FIRAuthUI.authUI()!
authUI.delegate = self

return true
}

我收到的错误是“无法将“AppDelegate”类型的值分配给“FIRAuthUIDelegate”类型” - 基本上我无法让以下行工作; authUI.delegate = self

我已阅读所有文档并浏览了项目 gitHub 存储库中有关实现的开放/已关闭问题: https://github.com/firebase/FirebaseUI-iOS/tree/master/FirebaseUI

我已经查看了之前的 StackOverflow 问题,该问题本质上与此处类似; How to use FirebaseUI for Google authentication on iOS in Swift?

我尝试从上面的 Stack Overflow 中复制代码,因为他声明他确实使用他的代码获得了更多显示选项(他的问题是关于身份验证的进一步错误),但我仍然遇到了同样的问题委托(delegate)错误。我尝试将 FIRAuthUIDelegate 分配给 AppDelegate 但它不符合要求。我错过了什么?

最佳答案

我也不熟悉 FirebaseUI,但这里有一个使用常规 Firebase 和 FBSDK 向 Facebook 授权用户的工作示例

@IBAction func fbButtonTapped(sender: UIButton) {
let facebookReadPermissions = ["email", "public_profile", "user_photos"]
FBSDKLoginManager().logInWithReadPermissions(facebookReadPermissions, fromViewController: self, handler: { (result:FBSDKLoginManagerLoginResult?, error:NSError?) -> Void in
if error != nil {
Helper.displayAlert("Error Logging into Facebook", message: error!.localizedDescription, viewController: self)
} else {
let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)
FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
if error != nil {
Helper.displayAlert("Error Logging into Facebook", message: error!.localizedDescription, viewController: self)
} else {
let request = FBSDKGraphRequest(graphPath:"me", parameters: ["fields": "id, first_name, last_name, email, age_range, gender, verified, timezone, picture"])
request.startWithCompletionHandler {
(connection, result, error) in
if error != nil {
print (error)
} else if let userData = result as? [String : AnyObject] {
guard let userID = FIRAuth.auth()?.currentUser?.uid else { return }
let userInfo = ["firstName": userData["first_name"] as! String, "lastName": userData["last_name"] as! String, "email": userData["email"] as! String,
"gender": userData["gender"] as! String, "id": userData["id"] as! String, "verified": userData["verified"]?.description as! AnyObject, "key": userID]


FirebaseData.fbData.createFirebaseUser(userID, user: userInfo)
self.performSegueWithIdentifier(self.loginSucessIdentifier, sender: nil)

}
}
}
}
}
})
}

func createFirebaseUser(uid: String, user: [String : AnyObject]) {
REF_USERS.child(uid).setValue(user)
}

可以稍微清理一下代码以删除所有 if let 语句,但它应该可以让您获得 facebook 登录的工作授权。

关于ios - 尝试通过 FirebaseUI Auth 连接 Facebook 登录,但遇到 authUI.delegate = self 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38044243/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com