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:

在这里输入图像描述

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:

在这里输入图像描述

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:

在这里输入图像描述

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


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

链接地址: http://www.djcxy.com/p/33258.html

上一篇: 如何从scrapy响应获取cookie并将cookie设置为下一个请求?

下一篇: 在iOS帐户选择器中