Dav*_*est 5 google-authentication google-login firebase swift firebase-authentication
我正在向我的应用程序介绍Google登录,虽然Google和Firebase文档都足够透彻,但我所做的并不充分......我仍然遇到此错误.希望这可以帮助其他人在实现他们的SDK时找到问题的解决方案....提前感谢审查这个大块的:
所以
App Delegate有以下内容,没有错误,但我注意到Facebook登录(正常工作)和新Google之间可能存在冲突,我不知道如何一起处理:
PS我没有在这里向AppDelegate添加GIDSignInDelegate,因为我正计划让我的VC处理登录逻辑,如下所示......
LoginVC 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
}
Run Code Online (Sandbox Code Playgroud)然后,从我所看到的......应该是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()
}
Run Code Online (Sandbox Code Playgroud)
百思不得其解?很抱歉这些人很久......但我已经完成了Firebase指南建议的所有内容,这意味着AppDelegate的Google文档中的逻辑就在ProfileVC中.有什么指针吗?
Kar*_*ngh -1
转到:将二进制文件与库链接。然后,单击“添加”,然后单击“添加其他”。按“Cmd + Shift + G”。然后,输入:“/usr/lib”。然后,单击“libz.1.dylib”。按确定添加,错误就会消失。此外,您可能还没有完成该协议附带的所有功能。您必须添加以下内容:
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
withError error: NSError!) {
if (error == nil) {
// Perform any operations on signed in user here.
} else {
print("\(error.localizedDescription)")
}
}
func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!,
withError error: NSError!) {
// Perform any operations when the user disconnects from app here.
// ...
}
Run Code Online (Sandbox Code Playgroud)
另外,请确保您已添加以下内容。桥接头中的行。
#import <GoogleSignIn/GoogleSignIn.h>
Run Code Online (Sandbox Code Playgroud)
更新:GIDSignInDelegate 无法添加到视图控制器。相反,您应该在 VC 中添加“GIDSignInUIDelegate”,并尝试在 App Delegate 中执行其他(Gidsigndwlwgate)操作。它会起作用的。
| 归档时间: |
|
| 查看次数: |
5749 次 |
| 最近记录: |