Google Account SignIn via installed Gmail App credentials in iOS












0















I have Google Sign In in my iOS Swift app. It is working fine but each and every time I need to enter email id and password. Same time, parallelly, I am using Gmail App in my iPhone. How can I use that Gmail credentials from my app and direct login? Is it possible by using Google-SignIn-iOS SDK?



I need this same for Google, FB, Outlook, Twitter, LinkedIn.



ViewController:



import GoogleSignIn

class ViewController: UIViewController, GIDSignInUIDelegate {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

GIDSignIn.sharedInstance().uiDelegate = self

}

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


func sign(inWillDispatch signIn: GIDSignIn!, error: Error!) {

}

func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!) {


}

func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!) {



}

}


AppDelegate:



import GoogleSignIn
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.


GIDSignIn.sharedInstance().clientID = "3578***********************.apps.googleusercontent.com"
GIDSignIn.sharedInstance().delegate = self

return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(url as URL?,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
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
// ...

print("emailemailemail ", email)
}
}

func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!,
withError error: Error!) {
// Perform any operations when the user disconnects from app here.
// ...
}
}









share|improve this question

























  • may be this may help developers.google.com/gmail/api/auth/about-auth

    – iOS_Developer
    Nov 20 '18 at 19:43
















0















I have Google Sign In in my iOS Swift app. It is working fine but each and every time I need to enter email id and password. Same time, parallelly, I am using Gmail App in my iPhone. How can I use that Gmail credentials from my app and direct login? Is it possible by using Google-SignIn-iOS SDK?



I need this same for Google, FB, Outlook, Twitter, LinkedIn.



ViewController:



import GoogleSignIn

class ViewController: UIViewController, GIDSignInUIDelegate {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

GIDSignIn.sharedInstance().uiDelegate = self

}

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


func sign(inWillDispatch signIn: GIDSignIn!, error: Error!) {

}

func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!) {


}

func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!) {



}

}


AppDelegate:



import GoogleSignIn
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.


GIDSignIn.sharedInstance().clientID = "3578***********************.apps.googleusercontent.com"
GIDSignIn.sharedInstance().delegate = self

return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(url as URL?,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
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
// ...

print("emailemailemail ", email)
}
}

func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!,
withError error: Error!) {
// Perform any operations when the user disconnects from app here.
// ...
}
}









share|improve this question

























  • may be this may help developers.google.com/gmail/api/auth/about-auth

    – iOS_Developer
    Nov 20 '18 at 19:43














0












0








0








I have Google Sign In in my iOS Swift app. It is working fine but each and every time I need to enter email id and password. Same time, parallelly, I am using Gmail App in my iPhone. How can I use that Gmail credentials from my app and direct login? Is it possible by using Google-SignIn-iOS SDK?



I need this same for Google, FB, Outlook, Twitter, LinkedIn.



ViewController:



import GoogleSignIn

class ViewController: UIViewController, GIDSignInUIDelegate {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

GIDSignIn.sharedInstance().uiDelegate = self

}

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


func sign(inWillDispatch signIn: GIDSignIn!, error: Error!) {

}

func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!) {


}

func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!) {



}

}


AppDelegate:



import GoogleSignIn
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.


GIDSignIn.sharedInstance().clientID = "3578***********************.apps.googleusercontent.com"
GIDSignIn.sharedInstance().delegate = self

return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(url as URL?,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
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
// ...

print("emailemailemail ", email)
}
}

func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!,
withError error: Error!) {
// Perform any operations when the user disconnects from app here.
// ...
}
}









share|improve this question
















I have Google Sign In in my iOS Swift app. It is working fine but each and every time I need to enter email id and password. Same time, parallelly, I am using Gmail App in my iPhone. How can I use that Gmail credentials from my app and direct login? Is it possible by using Google-SignIn-iOS SDK?



I need this same for Google, FB, Outlook, Twitter, LinkedIn.



ViewController:



import GoogleSignIn

class ViewController: UIViewController, GIDSignInUIDelegate {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

GIDSignIn.sharedInstance().uiDelegate = self

}

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


func sign(inWillDispatch signIn: GIDSignIn!, error: Error!) {

}

func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!) {


}

func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!) {



}

}


AppDelegate:



import GoogleSignIn
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.


GIDSignIn.sharedInstance().clientID = "3578***********************.apps.googleusercontent.com"
GIDSignIn.sharedInstance().delegate = self

return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(url as URL?,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
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
// ...

print("emailemailemail ", email)
}
}

func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!,
withError error: Error!) {
// Perform any operations when the user disconnects from app here.
// ...
}
}






ios swift gmail google-signin






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 5:55







McDonal_11

















asked Nov 20 '18 at 17:57









McDonal_11McDonal_11

2,06721334




2,06721334













  • may be this may help developers.google.com/gmail/api/auth/about-auth

    – iOS_Developer
    Nov 20 '18 at 19:43



















  • may be this may help developers.google.com/gmail/api/auth/about-auth

    – iOS_Developer
    Nov 20 '18 at 19:43

















may be this may help developers.google.com/gmail/api/auth/about-auth

– iOS_Developer
Nov 20 '18 at 19:43





may be this may help developers.google.com/gmail/api/auth/about-auth

– iOS_Developer
Nov 20 '18 at 19:43












1 Answer
1






active

oldest

votes


















1














follow these steps



Step 1



in your appdelegate add the client ID and deeplinking purpose add the return value in source application



import GoogleSignIn

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
GIDSignIn.sharedInstance().clientID = "3578***********************.apps.googleusercontent.com"
return true
}

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


for reusability purpose I created the common class for google signIn



import UIKit
import GoogleSignIn

class GoogleSDK: NSObject,GIDSignInDelegate,GIDSignInUIDelegate {
static let shared = GoogleSDK()
//MARK: Internal Properties
var signInBlock: ((GIDGoogleUser) -> Void)?

func googleSignIn() {
GIDSignIn.sharedInstance().delegate = self
// GIDSignIn.sharedInstance().signOut()
// GIDSignIn.sharedInstance().signIn()
GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/plus.login")
GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/plus.me")
if GIDSignIn.sharedInstance().hasAuthInKeychain() == true {
GIDSignIn.sharedInstance().signInSilently()
} else {
GIDSignIn.sharedInstance().signIn()
}
}

//Google SignIn Delegates
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if error == nil {
self.signInBlock?(user)

} else {
print("(error.localizedDescription)")
}
}

func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) {
// signInBlock(nil)
// if signInBlock != nil {
// signInBlock!(false, nil, error)
// }
}

}


on your current class invoke the NSObject call



 import GoogleSignIn

class ViewController: UIViewController, GIDSignInUIDelegate {

// call the following method where you need
// MARK: - Google Login
func GoogleLogin(){
// getTypeofLogin = getLoginType.Google.getName()
GIDSignIn.sharedInstance().uiDelegate = self
GoogleSDK.shared.googleSignIn()
GoogleSDK.shared.signInBlock = { (user) in
if !user.userID.isEmpty{
print(user)
//self.handleSocialLogin(UID: user.userID, UName: user.profile.name, UEmail: user.profile.email, loginType:getLoginType.Google.getName())
}
}
}

}


for logout use this



  GIDSignIn.sharedInstance().signOut()





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398839%2fgoogle-account-signin-via-installed-gmail-app-credentials-in-ios%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    follow these steps



    Step 1



    in your appdelegate add the client ID and deeplinking purpose add the return value in source application



    import GoogleSignIn

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    GIDSignIn.sharedInstance().clientID = "3578***********************.apps.googleusercontent.com"
    return true
    }

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


    for reusability purpose I created the common class for google signIn



    import UIKit
    import GoogleSignIn

    class GoogleSDK: NSObject,GIDSignInDelegate,GIDSignInUIDelegate {
    static let shared = GoogleSDK()
    //MARK: Internal Properties
    var signInBlock: ((GIDGoogleUser) -> Void)?

    func googleSignIn() {
    GIDSignIn.sharedInstance().delegate = self
    // GIDSignIn.sharedInstance().signOut()
    // GIDSignIn.sharedInstance().signIn()
    GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/plus.login")
    GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/plus.me")
    if GIDSignIn.sharedInstance().hasAuthInKeychain() == true {
    GIDSignIn.sharedInstance().signInSilently()
    } else {
    GIDSignIn.sharedInstance().signIn()
    }
    }

    //Google SignIn Delegates
    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
    if error == nil {
    self.signInBlock?(user)

    } else {
    print("(error.localizedDescription)")
    }
    }

    func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) {
    // signInBlock(nil)
    // if signInBlock != nil {
    // signInBlock!(false, nil, error)
    // }
    }

    }


    on your current class invoke the NSObject call



     import GoogleSignIn

    class ViewController: UIViewController, GIDSignInUIDelegate {

    // call the following method where you need
    // MARK: - Google Login
    func GoogleLogin(){
    // getTypeofLogin = getLoginType.Google.getName()
    GIDSignIn.sharedInstance().uiDelegate = self
    GoogleSDK.shared.googleSignIn()
    GoogleSDK.shared.signInBlock = { (user) in
    if !user.userID.isEmpty{
    print(user)
    //self.handleSocialLogin(UID: user.userID, UName: user.profile.name, UEmail: user.profile.email, loginType:getLoginType.Google.getName())
    }
    }
    }

    }


    for logout use this



      GIDSignIn.sharedInstance().signOut()





    share|improve this answer






























      1














      follow these steps



      Step 1



      in your appdelegate add the client ID and deeplinking purpose add the return value in source application



      import GoogleSignIn

      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
      // Override point for customization after application launch.
      GIDSignIn.sharedInstance().clientID = "3578***********************.apps.googleusercontent.com"
      return true
      }

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


      for reusability purpose I created the common class for google signIn



      import UIKit
      import GoogleSignIn

      class GoogleSDK: NSObject,GIDSignInDelegate,GIDSignInUIDelegate {
      static let shared = GoogleSDK()
      //MARK: Internal Properties
      var signInBlock: ((GIDGoogleUser) -> Void)?

      func googleSignIn() {
      GIDSignIn.sharedInstance().delegate = self
      // GIDSignIn.sharedInstance().signOut()
      // GIDSignIn.sharedInstance().signIn()
      GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/plus.login")
      GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/plus.me")
      if GIDSignIn.sharedInstance().hasAuthInKeychain() == true {
      GIDSignIn.sharedInstance().signInSilently()
      } else {
      GIDSignIn.sharedInstance().signIn()
      }
      }

      //Google SignIn Delegates
      func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
      if error == nil {
      self.signInBlock?(user)

      } else {
      print("(error.localizedDescription)")
      }
      }

      func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) {
      // signInBlock(nil)
      // if signInBlock != nil {
      // signInBlock!(false, nil, error)
      // }
      }

      }


      on your current class invoke the NSObject call



       import GoogleSignIn

      class ViewController: UIViewController, GIDSignInUIDelegate {

      // call the following method where you need
      // MARK: - Google Login
      func GoogleLogin(){
      // getTypeofLogin = getLoginType.Google.getName()
      GIDSignIn.sharedInstance().uiDelegate = self
      GoogleSDK.shared.googleSignIn()
      GoogleSDK.shared.signInBlock = { (user) in
      if !user.userID.isEmpty{
      print(user)
      //self.handleSocialLogin(UID: user.userID, UName: user.profile.name, UEmail: user.profile.email, loginType:getLoginType.Google.getName())
      }
      }
      }

      }


      for logout use this



        GIDSignIn.sharedInstance().signOut()





      share|improve this answer




























        1












        1








        1







        follow these steps



        Step 1



        in your appdelegate add the client ID and deeplinking purpose add the return value in source application



        import GoogleSignIn

        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        GIDSignIn.sharedInstance().clientID = "3578***********************.apps.googleusercontent.com"
        return true
        }

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


        for reusability purpose I created the common class for google signIn



        import UIKit
        import GoogleSignIn

        class GoogleSDK: NSObject,GIDSignInDelegate,GIDSignInUIDelegate {
        static let shared = GoogleSDK()
        //MARK: Internal Properties
        var signInBlock: ((GIDGoogleUser) -> Void)?

        func googleSignIn() {
        GIDSignIn.sharedInstance().delegate = self
        // GIDSignIn.sharedInstance().signOut()
        // GIDSignIn.sharedInstance().signIn()
        GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/plus.login")
        GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/plus.me")
        if GIDSignIn.sharedInstance().hasAuthInKeychain() == true {
        GIDSignIn.sharedInstance().signInSilently()
        } else {
        GIDSignIn.sharedInstance().signIn()
        }
        }

        //Google SignIn Delegates
        func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
        if error == nil {
        self.signInBlock?(user)

        } else {
        print("(error.localizedDescription)")
        }
        }

        func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) {
        // signInBlock(nil)
        // if signInBlock != nil {
        // signInBlock!(false, nil, error)
        // }
        }

        }


        on your current class invoke the NSObject call



         import GoogleSignIn

        class ViewController: UIViewController, GIDSignInUIDelegate {

        // call the following method where you need
        // MARK: - Google Login
        func GoogleLogin(){
        // getTypeofLogin = getLoginType.Google.getName()
        GIDSignIn.sharedInstance().uiDelegate = self
        GoogleSDK.shared.googleSignIn()
        GoogleSDK.shared.signInBlock = { (user) in
        if !user.userID.isEmpty{
        print(user)
        //self.handleSocialLogin(UID: user.userID, UName: user.profile.name, UEmail: user.profile.email, loginType:getLoginType.Google.getName())
        }
        }
        }

        }


        for logout use this



          GIDSignIn.sharedInstance().signOut()





        share|improve this answer















        follow these steps



        Step 1



        in your appdelegate add the client ID and deeplinking purpose add the return value in source application



        import GoogleSignIn

        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        GIDSignIn.sharedInstance().clientID = "3578***********************.apps.googleusercontent.com"
        return true
        }

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


        for reusability purpose I created the common class for google signIn



        import UIKit
        import GoogleSignIn

        class GoogleSDK: NSObject,GIDSignInDelegate,GIDSignInUIDelegate {
        static let shared = GoogleSDK()
        //MARK: Internal Properties
        var signInBlock: ((GIDGoogleUser) -> Void)?

        func googleSignIn() {
        GIDSignIn.sharedInstance().delegate = self
        // GIDSignIn.sharedInstance().signOut()
        // GIDSignIn.sharedInstance().signIn()
        GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/plus.login")
        GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/plus.me")
        if GIDSignIn.sharedInstance().hasAuthInKeychain() == true {
        GIDSignIn.sharedInstance().signInSilently()
        } else {
        GIDSignIn.sharedInstance().signIn()
        }
        }

        //Google SignIn Delegates
        func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
        if error == nil {
        self.signInBlock?(user)

        } else {
        print("(error.localizedDescription)")
        }
        }

        func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) {
        // signInBlock(nil)
        // if signInBlock != nil {
        // signInBlock!(false, nil, error)
        // }
        }

        }


        on your current class invoke the NSObject call



         import GoogleSignIn

        class ViewController: UIViewController, GIDSignInUIDelegate {

        // call the following method where you need
        // MARK: - Google Login
        func GoogleLogin(){
        // getTypeofLogin = getLoginType.Google.getName()
        GIDSignIn.sharedInstance().uiDelegate = self
        GoogleSDK.shared.googleSignIn()
        GoogleSDK.shared.signInBlock = { (user) in
        if !user.userID.isEmpty{
        print(user)
        //self.handleSocialLogin(UID: user.userID, UName: user.profile.name, UEmail: user.profile.email, loginType:getLoginType.Google.getName())
        }
        }
        }

        }


        for logout use this



          GIDSignIn.sharedInstance().signOut()






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 21 '18 at 6:12

























        answered Nov 21 '18 at 6:06









        Anbu.KarthikAnbu.Karthik

        60.6k16121111




        60.6k16121111






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398839%2fgoogle-account-signin-via-installed-gmail-app-credentials-in-ios%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            If I really need a card on my start hand, how many mulligans make sense? [duplicate]

            Alcedinidae

            Can an atomic nucleus contain both particles and antiparticles? [duplicate]