To solve your issue you need to do the following things :
- import the pod mentioned on the tutorial you have mentioned
- pod install
- in the appDelegate. swift import the following
import GoogleSignIn
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)
}
In your View controller make sure to include the following import
import FirebaseAuth
import GoogleSignIn
make sure that your View Controller implement the following
GIDSignInUIDelegate , GIDSignInDelegate
In the viewDidLoad function add the following:
GIDSignIn.sharedInstance().clientID = FIRApp.defaultApp()?.options.clientID
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().uiDelegate = self
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)")
}
}
In your storyboard add a view and make it extend from GIDSignInButton
class = GIDSignInButton
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.
// ...
}
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.