2

I'm using Swift 3 and trying Google Sign In With this tutorial

Created a bridging header file with:

#import <Google/SignIn.h>

My Build Settings reference the correct header file enter image description here

Yet when I go to implement the App Delegate I receive this error:

*Use of undeclared type GIDSignInDelegate*

enter image description here

What can I possibly be missing?

1
  • Double check the target membership of the file containing GIDSignInDelegate. Did you add it to your main target? Commented Feb 10, 2017 at 2:08

2 Answers 2

6

Please do not import any framework like google. Xcode automatically accesses required module if you have added correctly in the header bridge file.

and use following method to remove your error.

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

    if (error == nil) {
        // Perform any operations on signed in user here.
        let userId = user.userID                  // For client-side use only!
        let idToken = user.authentication.idToken // Safe to send to the server
        let fullName = user.profile.name
        let givenName = user.profile.givenName
        let familyName = user.profile.familyName
        let email = user.profile.email
        // ...
    } else {
        print("\(error.localizedDescription)")
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

To solve your issue you need to do the following things :

  1. import the pod mentioned on the tutorial you have mentioned
  2. pod install
  3. in the appDelegate. swift import the following import GoogleSignIn
  4. implement the following methods:

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
    {
        let handled = GIDSignIn.sharedInstance().handle(url, sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: [:])
        return handled
    }
    

and this function :

 func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        return GIDSignIn.sharedInstance().handle(url,sourceApplication: sourceApplication, annotation: annotation)
    }
  1. In your View controller make sure to include the following import

    import FirebaseAuth
    import GoogleSignIn
    
  2. make sure that your View Controller implement the following

    GIDSignInUIDelegate , GIDSignInDelegate

  3. In the viewDidLoad function add the following:

    GIDSignIn.sharedInstance().clientID = FIRApp.defaultApp()?.options.clientID
    GIDSignIn.sharedInstance().delegate = self
    GIDSignIn.sharedInstance().uiDelegate = self
    
  4. and finally implement the method SignIn

    func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {
    if (error == nil) {
      // Perform any operations on signed in user here.
      let userId = user.userID                  // For client-side use only!
      let idToken = user.authentication.idToken // Safe to send to the server
      let fullName = user.profile.name
      let givenName = user.profile.givenName
      let familyName = user.profile.familyName
      let email = user.profile.email
      // ...
    } else {
      print("\(error.localizedDescription)")
    }
    

    }

  5. In your storyboard add a view and make it extend from GIDSignInButton

    class = GIDSignInButton

  6. if you want to implement the sign out method : just add the following method to the same view controller

    func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!, withError error: NSError!) {
    // Perform any operations when the user disconnects from app here.
    // ...
    }
    
  7. Run the project, when you are in the view controller where you have added the above methods , you will get the google sign in button , click on it and a webView will be opened and finally sign in with your google account and you will be redirected back to the application

PS: I don't know why google called both of the signin and signout methods as SIGNIN , they need to change that in there libraries. for a better explanation you need to better read the tutorial that you have linked. If you have any question i'm looking forward to read your questions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.