小编JSD*_*JSD的帖子

在 Google 登录后使用 Swift 4 推送视图控制器

我正在使用 Firebase 和 Swift 4 来开发我的应用程序,但是在 Google 登录完成后我无法推送新的视图控制器。据我所知,我应该将 pushViewController 代码放在 didSignIn 方法中,但该部分在我的 AppDelegate.swift 文件中(因为它实现了 GIDSignInDelegate,根据 Firebase 文档)。

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

    guard let authentication = user.authentication else { return }
    let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken,
                                                   accessToken: authentication.accessToken)
    // ...
}
Run Code Online (Sandbox Code Playgroud)

现在,我想在登录完成后推送一个新的视图控制器,使用以下内容:

navigationController?.pushViewController(BrowserViewController(), animated: true)
Run Code Online (Sandbox Code Playgroud)

但是似乎不可能从 AppDelegate 文件中推送 VC,因为那里不存在 navigationController。我在不使用 Storyboards 的情况下以编程方式创建我的视图,所以我也无法执行 segues。

用户使用 Google Sign In 完成登录后,我如何能够展示新的 VC?我是否应该将 didSignInFor 方法移动到实际承载登录按钮的视图控制器(即使文档似乎没有说这是正确的方法)?

ios firebase swift firebase-authentication

2
推荐指数
1
解决办法
1669
查看次数

标签 统计

firebase ×1

firebase-authentication ×1

ios ×1

swift ×1