我正在向我的应用程序引入 Google 登录,虽然 Google 和 Firebase 文档都足够详尽,但我按照他们的建议所做的工作还不够......我仍然收到此错误。希望这能帮助其他人在实现 SDK 时找到问题的解决方案......提前感谢您审阅这一厚重的内容:
这是Firebase 指南 https://www.firebase.com/docs/ios/guide/login/google.html和谷歌指南: https://developers.google.com/identity/sign-in/ios/sign-in?ver=swift
So
- Added 谷歌到 podfile - CHECK
- 添加行到桥接头 - CHECK
- Added GoogleService-Info.plist& 捆绑包标识符 & 反向客户端 IDURL方案 - CHECK
-
应用程序委托有以下内容,没有错误,但我注意到 Facebook 登录(正常工作)和新的 Google 之间可能存在冲突,我不知道如何一起处理:
P.S.我在这里没有将 GIDSignInDelegate 添加到 AppDelegate,因为我计划让我的 VC 处理登录逻辑,如下所示......
-
登录VC ViewController代码在这里:
class LoginVC: UIViewController, UIViewControllerTransitioningDelegate, UITextViewDelegate, UITextFieldDelegate, GIDSignInDelegate, GIDSignInUIDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let ref = Firebase(url: "https://MYAPPID.firebaseio.com")
GIDDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().signInSilently() // for if the user has recently been authenticated
}
然后,据我所知......应该是 Google 需要与 Firebase 对话的一切:
// Implementing the required GIDSignInDelegate methods
func googleSignIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {
if (error == nil) {
// Auth with Firebase
let userId = user.userID
let idToken = user.authentication.idToken
let fullName = user.profile.name
let givenName = user.profile.givenName
let familyName = user.profile.familyName
let email = user.profile.email
ref.authWithOAuthProvider("google", token: user.authentication.accessToken, withCompletionBlock: { (error, authData) in
// User is logged in!
})
} else {
print("\(error.localizedDescription)")
}
}
func googleSignOut() {
GIDSignIn.sharedInstance().signOut()
ref.unauth()
}
// Implement the required GIDSignInDelegate methods and Unauth when disconnected from Google
func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!, withError error: NSError!) {
ref.unauth()
}
// IBAction to handle the sign-in process
@IBAction func googleButtonPressed(sender: TKTransitionSubmitButton!) {
GIDSignIn.sharedInstance().signIn()
}
困惑吗?对不起,各位,我已经完成了 Firebase 指南建议的所有内容,这意味着 AppDelegate 的 Google 文档中的逻辑都在 ProfileVC 中。有什么指点吗?
这说明你的类还没有实现你所需的方法GIDSignInDelegate
。 Swift 3 中方法名称发生了重大变化。所以你的新方法将是
公共功能签名(_登录:GIDSignIn!,didSignInFor用户:
GIDGoogleUser!,withError 错误:NSError!)
Please check Library screen shot. So In
is missing in new swift 3 convention of naming of methods or classes.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)