Google通过Firebase登录:GIDSignInDelegate不符合ViewController

Dav*_*est 5 google-authentication google-login firebase swift firebase-authentication

我正在向我的应用程序介绍Google登录,虽然Google和Firebase文档都足够透彻,但我所做的并不充分......我仍然遇到此错误.希望这可以帮助其他人在实现他们的SDK时找到问题的解决方案....提前感谢审查这个大块的:

错误图片

以下是Firebase指南Google指南:

所以

  1. Google添加到podfile - CHECK
  2. Bridging-Header中添加了一行- CHECK
  3. 添加了GoogleService-Info.plist和捆绑包标识符以及反向客户端ID到URL方案 - CHECK
  4. App Delegate有以下内容,没有错误,但我注意到Facebook登录(正常工作)和新Google之间可能存在冲突,我不知道如何一起处理:

    代码添加到AppDelegate  - 抱歉没有在这里写,StackOverflow格式化在这个场合讨厌我

    PS我没有在这里向AppDelegate添加GIDSignInDelegate,因为我正计划让我的VC处理登录逻辑,如下所示......

  5. 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中.有什么指针吗?

Sus*_*nta 5

这是说你的班级没有为你的实施所需的方法GIDSignInDelegate.Swift 3中的方法名称有重大变化.所以你的新方法将是

public func sign(_ signIn:GIDSignIn!,didSignInFor user:GIDGoogleUser!,withError error:NSError!)

请检查库屏幕截图.因此In,在方法或类的命名新swift 3约定中缺少. 在此输入图像描述


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)操作。它会起作用的。