Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm introducing Google Sign-In to my app and whilst both Google and Firebase documentation is thorough enough, what I have done as they suggested is not sufficient... I am still getting this error. Hopefully this will help others with finding a solution to the problem when implementing their SDK....thanks in advance for reviewing this chunky one:

Error Image

Here's the Firebase guide and the Google guide:

So

  1. Added Google to podfile - CHECK
  2. Added line into Bridging-Header - CHECK
  3. Added GoogleService-Info.plist & bundle identifier & reversed client ID to URL schemes - CHECK
  4. App Delegate has the following, with no errors but I notice there are likely to be conflicts between Facebook login (working correctly) and newly Google, which I've no idea how to handle together:

    Code added to AppDelegate - sorry not written in here, StackOverflow formatting was hating me on this occasion

    P.S. I have NOT added GIDSignInDelegate to AppDelegate here because I am planning for my VC to handle the login logic, as you will see below...

  5. LoginVC ViewController code here:

    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
        }
    

Then this, which from what I can see... should be everything Google needs to talk to 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()
        }

Baffled? Sorry for the long one guys...but I've done everything the Firebase guide suggests and that means the logic in the Google doc for AppDelegate is all there in the ProfileVC. Any pointers?

like image 257
David West Avatar asked Mar 29 '16 23:03

David West


1 Answers

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. enter image description here

like image 107
Susim Samanta Avatar answered Oct 20 '22 00:10

Susim Samanta