gpt4 book ai didi

ios - 更改谷歌登录 ios 上的 View

转载 作者:行者123 更新时间:2023-11-29 00:51:28 28 4
gpt4 key购买 nike

我已将 Google 登录添加到我的应用程序中,该应用程序正在运行,但我似乎无法在以编程方式成功登录后更改我的 View 。

这是我的演示 Storyboard。灰色框是登录按钮,我添加了一个“手动移动页面”按钮,带有从登录屏幕到选项卡栏 Controller 屏幕的 segue。单击此按钮按预期工作,我需要在应用检测到用户已登录时自动执行相同操作。

当用户打开应用程序时,第一个屏幕是 View Controller “登录屏幕”,如果用户已通过以下代码检查登录,我想将它们转发到主屏幕(第一个选项卡)。如果可能的话,请告诉我是否有更好/更快的方法。

Storyboard

登录屏幕:

override func viewDidLoad() {
super.viewDidLoad()

// Google sign in
GIDSignIn.sharedInstance().uiDelegate = self
// Check if they're already signed in
GIDSignIn.sharedInstance().signInSilently()

// check if the user is signed in
if (GIDSignIn.sharedInstance().hasAuthInKeychain()){
print("signed in")
// Forward the user here straight away...
} else {
print ("not signed in")
// Need to handle the forwarding once they sign in.
}
}

最佳答案

您可以从登录屏幕添加 Segue 到您想要的任何 ViewController 并像这样编写代码:

if (GIDSignIn.sharedInstance().hasAuthInKeychain()){
print("signed in")
performSegueWithIdentifier("your_segue_name", sender: self)
// Forward the user here straight away...
}

或者您可以通过以下方式模态显示 ViewController:

if (GIDSignIn.sharedInstance().hasAuthInKeychain()){
let storyboard = UIStoryboard(name: "Yourstoryboardname(Example: Main)", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("yourviewcontrollertobepresented") as! UIViewController
self.presentViewController(vc, animated: true, completion: nil)
}

您需要NAME 您想要显示的 View Controller 。为此,您在 Storyboard中单击您的 ViewController,然后在 Identity inspector 中您会找到 Storyboard ID。将其命名为您想要的名称,并在 instantiateViewControllerWithIdentifier("yourviewcontrollertobepresented")

中指定相同的名称

关于ios - 更改谷歌登录 ios 上的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38107355/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com