1

Google signing (GIDSignIn) working perfectly until iOS 10.3, but not in iOS 11.

In iOS 11:

- (void)signIn:(GIDSignIn *)signIn presentViewController:(UIViewController *)viewController

method is called only the first time. Subsequent login tries (after signout or cancel signin) are not invoking the above call back. Call to GIDSignIn.signin method does nothing.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user516542
  • 107
  • 2
  • 8

2 Answers2

0

Basically you not call the two delegates into you Viewcontroller.Swift file

Xcode 9.2 Swift 4

Step 1 : Install two pods

pod 'Google'
pod 'Google/SignIn'

Step 2 : Enable Google Sign by giving your bundle identifier of your project. Generate configuration file and import it into your project.

Step 3 : Go to your AppDelegate.swift and import two libraries.

import GoogleSignIn
import Google

Step 4 : Replace you appDelegate function by this code.Client ID is show in your Google GoogleService-Info.plist which you import into your project.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
         GIDSignIn.sharedInstance().clientID = "CLIENT_ID"
        return true
    }

Implement this delegate in your AppDelegate file.GIDSignInDelegate

class AppDelegate: UIResponder, UIApplicationDelegate,GIDSignInDelegate {

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
            if let error = error {
                print("\(error.localizedDescription)")

            } else {
                // 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
            }

       }

   func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {

        let googleDidHandle = GIDSignIn.sharedInstance().handle(url,
                                                                sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
                                                                annotation: options[UIApplicationOpenURLOptionsKey.annotation])
        return googleDidHandle

    }
}

Step 5 : Go to ViewController.Swift file paste the code and drag the button and connect with button action which is available in code.You only need to connect button with code

import UIKit
import GoogleSignIn
import Google

class ViewController: UIViewController,GIDSignInUIDelegate, GIDSignInDelegate {

    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
        if (error == nil) {
            // Perform any operations on signed in user here.
            print(user.userID)                // For client-side use only!
            print(user.authentication.idToken) // Safe to send to the server
            print(user.profile.name)
            print(user.profile.givenName)
            print(user.profile.familyName)
            print(user.profile.email)
            print(user.authentication.accessToken)
            print(user.profile)

        } else {
            print("\(error.localizedDescription)")
        }
    }
    func sign(_ signIn: GIDSignIn!, didDisconnectWith user:GIDGoogleUser!,
              withError error: Error!) {
    }
    @IBAction func onBtnTapGmailLogin(sender: GIDSignInButton) {
        GIDSignIn.sharedInstance().signIn()
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        GIDSignIn.sharedInstance().uiDelegate = self
        GIDSignIn.sharedInstance().delegate = self
        var configureError:NSError?
        GGLContext.sharedInstance().configureWithError(&configureError)

        assert(configureError == nil, "Error configuring Google services: \(configureError)")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}
Khawar Islam
  • 2,556
  • 2
  • 34
  • 56
0

just two days back only solved this issue. Please find below links which might help you to understand what's needed. Where as most important thing is your view controller from which you are performing an action to open GSignIn that VC must have to be in UINavigationStack for iOS 10 and greater. Links: Google Sign In showing blank screen in iOS , GIDSignIn white screen on iOS 9

Fatin Wasta
  • 424
  • 1
  • 6
  • 20