Google登录iOS帐户选择器

Nim*_*myz 7 android login ios

我在我的iOS应用中使用Google登录.我按照Google教程(https://developers.google.com/identity/sign-in/ios/sign-in#add_the_sign-in_button)使用了用户必须点击的GIDSignInButton.当他点击它时,他被重定向到Safari,如下所示:

在此输入图像描述

这个问题是我有多个Google帐户,并且希望能够选择我想要使用的帐户.现在它只需要自动执行其中一个,我所要做的就是按"拒绝"或"允许".此外,我不喜欢该应用程序被重定向到Chrome的事实.理想情况下,我想要的是Google Hangouts应用程序在iOS上的功能:

在此输入图像描述

它会向您显示以前用于登录任何Google应用的所有帐户,并让您在不离开应用的情况下决定使用该应用的哪些帐户.在Android上我得到了类似的东西为我的应用程序工作:

在此输入图像描述

如何在我的iOS应用程序中实现这种行为(不要离开app +帐户选择器)?

Jon*_*ing 3

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)
}
Run Code Online (Sandbox Code Playgroud)

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.

请记住,无论您最终选择什么选项,您仍然需要遵守 OAuth 2.0。我建议如果可能的话,使用 Google 为 iOS 开发人员构建的东西。当选择与默认帐户不同的帐户时,如果您选择遵循指南并执行 Google 为 iOS 开发人员创建的操作,那么您只需点击个人资料图片即可切换帐户。

长话短说

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