gpt4 book ai didi

swift - 从 App Delegate 执行 Segue - Swift

转载 作者:行者123 更新时间:2023-11-28 05:57:26 25 4
gpt4 key购买 nike

我正在使用 Firebase 和 GoogleSignIn 将用户注册到我的 iOS 应用程序。我已经按照指示在 AppDelegate.swift 文件中编写了所有代码。登录成功后,我想将用户带到另一个ViewController。我当前的代码是;

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if (error) != nil {
return
}

print("User signed into Google")
guard let authentication = user.authentication else { return }
let credential = FIRGoogleAuthProvider.credential(withIDToken: authentication.idToken,
accessToken: authentication.accessToken)

FIRAuth.auth()?.signIn(with: credential, completion: { (user, error) in
print("User Signed In to Firebase")

self.databaseRef = FIRDatabase.database().reference()

self.databaseRef.child("Google User Profiles").child(user!.uid).observeSingleEvent(of: .value, with: { (snapshot) in

let snapshot = snapshot.value as? NSDictionary

if(snapshot == nil)
{
self.databaseRef.child("Google User Profiles").child(user!.uid).child("name").setValue(user?.displayName)
self.databaseRef.child("Google User Profiles").child(user!.uid).child("email").setValue(user?.email)
}


})

})
}

最佳答案

首先,进入您的 Storyboard并为您的 viewController 设置一个 Storyboard ID。 Storyboard ID接下来,进入您的 viewController 并将此方法添加到您的类中。

import UIKit

class ViewController2: UIViewController {

// Change the name of the storyboard if this is not "Main"
// identifier is the Storyboard ID that you put juste before
class func instantiate() -> ViewController2 {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "\(ViewController2.self)") as! ViewController2

return viewController
}

}

然后,在您的应用委托(delegate)中,当您想要显示 viewController 时执行

window?.rootViewController = ViewController2.instantiate()

关于swift - 从 App Delegate 执行 Segue - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51041739/

25 4 0
文章推荐: css - 在 Zend Framework 2 分页中更改样式
文章推荐: ios - 更改 UINavigationController 颜色和字体
文章推荐: html - 中的自定义单元格/边框间距