Google Sign-In via Firebase: GIDSignInDelegate does not conform to ViewController

隐身守侯 提交于 2019-12-05 08:44:17

It's saying your class have not implemented required method for your GIDSignInDelegate. There are major change in name of method in Swift 3. So your new method will be

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

Please check Library screen shot. So In is missing in new swift 3 convention of naming of methods or classes.

I found needed methods by typing "func s" and searching in suggestions box

Oh, I miss Alt+Enter feature in Android Studio

(BTW this is for Swift 3 in XCode 8 beta)

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: NSError!) {
        let authentication = user.authentication
        let credential = FIRGoogleAuthProvider.credential(withIDToken: (authentication?.idToken)!,
                                                          accessToken: (authentication?.accessToken)!)
        let comp:FIRAuthResultCallback = { (user:FIRUser?, error:NSError?) in
            if error == nil {
                DataStorage.inst.user.id = user?.uid
            }
        }
        FIRAuth.auth()?.signIn(with: credential, completion: comp)
    }

    func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: NSError!) {

    }

Just replace

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)")
    }}

with

public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
    //Code
}

Just add

#import "GoogleSignIn/GoogleSignIn.h"

to your Bridging header file and hit shift + cmd + k to clean.

Go to: Link Binary with Libraries. Then, Click on Add, then Add Other. Press "Cmd + shift + G". Then, type: "/usr/lib". Then, Click on "libz.1.dylib". Press Ok to add and the errors will go away. Also, you are probably not completing all the functions that come along with this protocol. You will have to add following:

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.
        // ...
}

Also, make sure you have added the foll. line in Bridging Header.

#import <GoogleSignIn/GoogleSignIn.h>

UPDATE: GIDSignInDelegate can't be added to View Controller. Instead, you should add "GIDSignInUIDelegate" in VC and try to perform other(Gidsigndwlwgate) operations in App Delegate. It will work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!