首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Firebase Google LogIn Xcode11之后的Segue

Firebase Google LogIn Xcode11之后的Segue
EN

Stack Overflow用户
提问于 2020-03-31 03:38:35
回答 1查看 147关注 0票数 0

我在这方面是新手,我正在寻找一个解决方案,以进入一个新的视图控制器登录后与谷歌。我想,登录是有效的,但是3天后我没有成功。我想在登录后进入其他空白的视窗控制器。我尝试了许多解决方案,可以在stackoverflow和google文档中找到,但似乎没有适用于我的Xcode版本的文档。

这是我的AppDelegate:

代码语言:javascript
复制
import UIKit
import Firebase
import GoogleSignIn
import FirebaseUI

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {



    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        FirebaseApp.configure()
        GIDSignIn.sharedInstance()?.clientID = FirebaseApp.app()?.options.clientID
        GIDSignIn.sharedInstance()?.delegate = self

        return true
    }

    // MARK: UISceneSession Lifecycle

    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
        if let error = error {
            if (error as NSError).code == GIDSignInErrorCode.hasNoAuthInKeychain.rawValue {
              print("The user has not signed in before or they have since signed out.")
            } else {
              print("\(error.localizedDescription)")
            }
            return
          }
            let userId = user.userID                  // For client-side use only!
            let idToken = user.authentication.idToken // Safe to send to the server
            let fullName = user.profile.name
            let givenName = user.profile.givenName
            let familyName = user.profile.familyName
            let email = user.profile.email
                print(fullName)

        guard let authentication = user.authentication else { return }
        let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)

        Auth.auth().signIn(with: credential) { (authResult, error) in
            if let error = error {
                print("firebase sign in error")
                print(error)
                return
            } else {
            print("user is signed in with Firebase")

            }

        }

    func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any])
      -> Bool {
      return GIDSignIn.sharedInstance().handle(url)
    }



    }

}

这是我的ViewController

代码语言:javascript
复制
import Firebase
import GoogleSignIn
import UIKit
import FirebaseAuth

class ViewController: UIViewController{


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

        GIDSignIn.sharedInstance()?.presentingViewController = self
        GIDSignIn.sharedInstance()?.signIn()
        GIDSignIn.sharedInstance()?.restorePreviousSignIn()
        super.viewDidAppear(true)


        let gSignIn = GIDSignInButton(frame: CGRect(x: 0,y: 0, width: 230, height: 48))
        gSignIn.center = view.center
        view.addSubview(gSignIn)
    }

}

如果有人能帮上忙,我将非常感谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-01 03:59:19

如下所示:

代码语言:javascript
复制
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
var vc: UIViewController?
vc = storyboard.instantiateViewController(withIdentifier: "signed")
window?.rootViewController = vc
window?.makeKeyAndVisible()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60938241

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档