Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 谷歌登录集成问题_Ios_Swift_Integration_Google Signin - Fatal编程技术网

Ios 谷歌登录集成问题

Ios 谷歌登录集成问题,ios,swift,integration,google-signin,Ios,Swift,Integration,Google Signin,我试图在代码中实现。当用户完成登录过程时,我将如何转到另一个控制器。但我在谷歌上没有找到任何完美的解决方案。我能为这类问题做些什么。如果你对我有什么建议,请帮忙 这是ViewController.swiftcode我一步一步地把所有代码放进去 import UIKit import GoogleSignIn class ViewController: UIViewController, GIDSignInUIDelegate, GIDSignInDelegate { @IBOutle

我试图在代码中实现。当用户完成登录过程时,我将如何转到另一个控制器。但我在谷歌上没有找到任何完美的解决方案。我能为这类问题做些什么。如果你对我有什么建议,请帮忙

这是
ViewController.swift
code我一步一步地把所有代码放进去

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
code

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!, dismiss viewController: UIViewController!) {
    self.viewController!.dismiss(animated: true, completion: nil)
}
它是GIDSignInUIDelegate之一,在用户签名后,它将工作,因为您可以使用它导航到任何视图控制器。

尝试此代码

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)
}

你面临的问题是什么?@Kuldeep实际上,当用户完成登录时,我想去另一个控制器。我该怎么做?取消注释
self.performsgue(带标识符:“”,发件人:self)
并添加
identifier
@Kuldeep我取消注释它。但当我点击登录按钮时。在签到之前,另一个控制员会去。我想在登录之后。我正在尝试此代码,但它现在工作正常。当我点击登录按钮时。在签到之前,另一个控制员会去。如果在登录之前调用此func
didsignin
,请确保用户logoutI正在新设备上运行,并且用户未登录该设备。还是那个问题。@VeerendraPratapsingh,编辑答案,现在试试,我确信它能正常工作