gpt4 book ai didi

ios - Google 登录集成问题

转载 作者:行者123 更新时间:2023-11-28 07:49:56 24 4
gpt4 key购买 nike

我尝试在我的代码中实现。当用户完成登录过程时,我将如何转到另一个 Controller 。但是我没有在谷歌上得到任何完美的解决方案。我能为这类问题做些什么。如果您对我有任何建议,请提供帮助。

这是ViewController.swift代码我把所有的代码一步步放上来

import UIKit
import GoogleSignIn

class ViewController: UIViewController, GIDSignInUIDelegate, GIDSignInDelegate {

@IBOutlet weak var btnOutLet: UIButton!

override func viewDidLoad() {
super.viewDidLoad()

GIDSignIn.sharedInstance().clientID = "KEY"

GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().delegate = self
}

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {

if error != nil
{
print(error)
return
}
else
{
print(user.profile.email)
//self.performSegue(withIdentifier: "", sender: self)
}
}

@IBAction func btnAction(_ sender: Any) {
GIDSignIn.sharedInstance().signIn()
}

}

这是Appdelegate代码

import UIKit
import GoogleSignIn

@UIApplicationMainclass AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(url,sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}

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

}

最佳答案

试试这个代码

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {

if error == nil
{

print(user.profile.email)

DispatchQueue.main.asyncAfter(deadline: .now() + 0.35) {
self.performSegue(withIdentifier: "youridentifier", sender: self)
}


}
else
{
print(error)
}
}

func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!) {
self.present(viewController, animated: true, completion: nil)
}

func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!) {
viewController.dismiss(animated: true, completion: nil)
}

关于ios - Google 登录集成问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49995095/

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