Google Account SignIn via installed Gmail App credentials in iOS
up vote
0
down vote
favorite
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
add a comment |
up vote
0
down vote
favorite
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
may be this may help developers.google.com/gmail/api/auth/about-auth
– iOS_Developer
Nov 20 at 19:43
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
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
ios swift gmail google-signin
edited Nov 21 at 5:55
asked Nov 20 at 17:57
McDonal_11
2,02921234
2,02921234
may be this may help developers.google.com/gmail/api/auth/about-auth
– iOS_Developer
Nov 20 at 19:43
add a comment |
may be this may help developers.google.com/gmail/api/auth/about-auth
– iOS_Developer
Nov 20 at 19:43
may be this may help developers.google.com/gmail/api/auth/about-auth
– iOS_Developer
Nov 20 at 19:43
may be this may help developers.google.com/gmail/api/auth/about-auth
– iOS_Developer
Nov 20 at 19:43
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
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()
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
up vote
1
down vote
accepted
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()
add a comment |
up vote
1
down vote
accepted
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()
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
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()
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()
edited Nov 21 at 6:12
answered Nov 21 at 6:06
Anbu.karthik
60.1k16121111
60.1k16121111
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
may be this may help developers.google.com/gmail/api/auth/about-auth
– iOS_Developer
Nov 20 at 19:43