I am trying to use google sign in as per the instructions given on the firebase authentication for swift iOS
https://firebase.google.com/docs/auth/ios/google-signin
But following all the instructions still not able to perform the google sign in/ up. When the google sign in button is pressed, it takes to the google authentication page , where I do choose the gmail id/ type and sign in gmail id, but after doing that it doesn't register with the gmail id in firebase.
Below is the code I am using
AppDelegate.swift
internal func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
GIDSignIn.sharedInstance().delegate = self
let authListener = Auth.auth().addStateDidChangeListener { auth, user in
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if user != nil {
//
let pushManager = PushNotificationManager(userID: Auth.auth().currentUser!.uid)
pushManager.registerForPushNotifications()
} else {
// menu screen
}
}
return true
}
@available(iOS 9.0, *)
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any])
-> Bool {
return GIDSignIn.sharedInstance().handle(url)
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return GIDSignIn.sharedInstance().handle(url)
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) {
// ...
if let error = error {
// ...
return
}
guard let authentication = user.authentication else { return }
let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken,
accessToken: authentication.accessToken)
// ...
}
ViewController.Swift
override func viewDidLoad() {
super.viewDidLoad()
GIDSignIn.sharedInstance()?.presentingViewController = self
GIDSignIn.sharedInstance().signIn()
}
I did implemented GIDSignInDelegate in AppDelegate, Enabled the Google Sign in Firebase Authentication. Created button on storyboard as per the instructions in the above link. I did configured reverse client id as well. Still not able to sign in/up.
Please help. Thanks in Advance.
Auth.auth().signIn(with: credential). Calling this code block will handle the actual Firebase sign in. - kobowo