I can do authentication for single account using GIDSignIn
by below code.
GIDSignIn *googleSignIn = [GIDSignIn sharedInstance];
googleSignIn.delegate = self;
googleSignIn.uiDelegate = self;
googleSignIn.clientID = (NSString*)cGmailAppClientId;
googleSignIn.scopes = [self getGmailAuthenticationScopes];;
[googleSignIn signIn];
But GIDSignIn
is shared instance. It is for an only one account. How can I add multiple accounts? Multiple accounts should accessible concurrently (Ex getting access token).
Related SO question doesn't give correct idea.
I don't think GIDSignIn
supports multiple accounts. While in theory you could instantiate instances other than the sharedInstance
, only one authorization will be persisted to the iOS keychain at a time. (The library would need multiple keys to save multiple authorizations, but if you instantiated multiple instances, how could it know which was which after a cold launch?)
Fortunately, there's Google's GTMAppAuth
, an alternative library that fulfills the same purpose. It's a bit more complicated to use than GIDSignIn
, but works in generally the same fashion. The key differentiators are that 1) you can create multiple authorizations at a time, and 2) you can persist them to the iOS keychain with keys of your choosing. If you're interested specifically in accessing Gmail, then these steps from the popular MailCore2 library may be helpful.
It sounds from this thread like the libraries are supported by different teams within the company, but I suspect it will be a while before they converge, if ever.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With