在iOS帐户选择器中

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

在这里输入图像描述

问题在于我拥有多个Google帐户,并希望能够选择我想使用的帐户。 现在只需要其中一个,我只需按“拒绝”或“允许”即可。 另外,我不喜欢该应用被重定向到Chrome的事实。 理想情况下,我想要的就像Google环聊应用在iOS上所做的一样:

在这里输入图像描述

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

在这里输入图像描述

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


他们能够在Google环聊中这样做的原因是因为它是由Google制作的。 公司并不总是向开发者提供所有功能,这就是它的一个主要例子。 你在Android上能够做到这一点的原因是因为谷歌决定允许开发者更多地访问不同的功能。 毕竟,android是由Google开发的。 现在至于不离开应用程序,你总是可以使用嵌入式Web视图。 这将使用户保持在应用程序中,而是以模态方式弹出Web视图。 这不是世界上最好的,但比用户发送到其他地方要好。 你有没有试过这段代码:

// 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)
}

我在您发布的链接中发现了这一点。 我没有运行或测试代码,但它似乎呈现一个视图控制器,而不是将您发送到Safari浏览器。 这可能更符合你想要的内容。

回答@山姆的问题:

“如何通过现有已安装的Google应用登录Google,而不是在Safari中打开网址?”

你可能可以用android完成这个,但不能用iOS。 这是因选择平台而受到限制的另一个示例。

请记住,最终选择的任何选项仍需遵守OAuth 2.0。 我建议尽可能使用Google为iOS开发人员构建的内容。 当选择与默认帐户不同的帐户时,如果您选择遵循指南并执行Google为iOS开发者创建的内容,则只需点击个人资料图片并切换帐户即可。

TL; DR

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

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

上一篇: in iOS account picker

下一篇: Data structure for quick match in a card game