Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sign-in iOS account picker

I'm using Google Sign-in in my iOS app. I followed the Google tutorial (https://developers.google.com/identity/sign-in/ios/sign-in#add_the_sign-in_button) which uses a GIDSignInButton that the user has to click. When he clicks it he is redirected to Safari which looks like this:

enter image description here

The problem with this is that I have multiple Google accounts and would like to be able to pick which one I want to use. Now it just takes one of them automatically and all I have to do is press "deny" or "allow". Also, I don't like the fact that the app gets redirected to Chrome. Ideally what I would want is something like the Google Hangouts app does on iOS:

enter image description here

It shows you all the accounts that you have used to sign in to any Google app previously and lets you decide which ones the use with the app without leaving the app. On Android I got something similar working for my app:

enter image description here

How can I achieve this kind of behaviour (don't leave app + account chooser) in my iOS app?

like image 664
Nimyz Avatar asked Apr 06 '16 13:04

Nimyz


People also ask

How do I sign into Google on iOS?

On your iPhone or iPad, open the Safari app. Go to www.google.com. Tap your profile image or Sign in. Follow the sign-in steps.

What is reversed client ID?

The reversed client ID is your client ID with the order of the dot-delimited fields reversed. For example: com.googleusercontent.apps.1234567890-abcdefg.

How do I log into Google firebase Swift?

If you haven't yet connected your app to your Firebase project, do so from the Firebase console. Enable Google as a sign-in method in the Firebase console: In the Firebase console, open the Auth section. On the Sign in method tab, enable the Google sign-in method and click Save.


1 Answers

The reason they are able to do that in Google Hangouts is because it's made by Google. Companies don't always make every feature available to developers and this is a prime example of it. The reason you were able to do this in android was because Google decided to allow developers more access to different features. After all, android is developed by Google. Now as for not leaving the app you could always use an embedded web view. This will keep the user in the app and instead pop up a web view modally. It's not the best in the world, but is better than having the user sent somewhere else. Have you tried this code:

// Implement these methods only if the GIDSignInUIDelegate is not a subclass of
// UIViewController.

// Stop the UIActivityIndicatorView animation that was started when the user
// pressed the Sign In button
func signInWillDispatch(signIn: GIDSignIn!, error: NSError!) {
  myActivityIndicator.stopAnimating()
}

// Present a view that prompts the user to sign in with Google
func signIn(signIn: GIDSignIn!,
    presentViewController viewController: UIViewController!) {
  self.presentViewController(viewController, animated: true, completion: nil)
}

// Dismiss the "Sign in with Google" view
func signIn(signIn: GIDSignIn!,
    dismissViewController viewController: UIViewController!) {
  self.dismissViewControllerAnimated(true, completion: nil)
}

I found this on the link that you posted. I haven't run or tested the code but it appears to present a view controller instead of sending you to safari. This may be more along the lines of what you want.

To answer @Sam's question:

"How to login Google by existing installed Google apps rather than opening URL in Safari?"

You could probably accomplish this with android but not with iOS. This another example of something that is restricted because of the platform selected.

Remember whatever option you end up choosing you will still be required to adhere to OAuth 2.0. I would suggest if at all possible using what Google has built out for iOS developers to use. When it comes to selecting a different account than the default one, if you chose to follow the guide and do what Google created for iOS developers, then you can simply tap on the profile image and switch accounts.

TL;DR

https://www.youtube.com/watch?time_continue=227&v=-26DGO_E1ds

like image 123
Jonah Starling Avatar answered Oct 03 '22 02:10

Jonah Starling