Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.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注册移动到MainTabBarController_Ios_Swift_Firebase - Fatal编程技术网

谷歌ios注册移动到MainTabBarController

谷歌ios注册移动到MainTabBarController,ios,swift,firebase,Ios,Swift,Firebase,好消息是,整个注册部分工作得很好,但我似乎无法从AppDelegate.swift部分移动到MainTabBarController(我正试图移动到的应用程序部分)在模拟器中,我得到的错误是,类型为“AppDelegate”的值没有成员“Disclose”,每当我尝试将代码移动到应用程序的另一个部分到注册部分时,它就不起作用,我必须将其包含在AppDelegate中 @UIApplicationMain class AppDelegate: UIResponder, UIApplicationD

好消息是,整个注册部分工作得很好,但我似乎无法从AppDelegate.swift部分移动到MainTabBarController(我正试图移动到的应用程序部分)在模拟器中,我得到的错误是,类型为“AppDelegate”的值没有成员“Disclose”,每当我尝试将代码移动到应用程序的另一个部分到注册部分时,它就不起作用,我必须将其包含在AppDelegate中

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate,   GIDSignInDelegate {



func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
    if let err = error {
        print("Failed to Login to Google", err)
        return
    }

    print("Successfully logged into Google", user)

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

    Auth.auth().signInAndRetrieveData(with: credential) { (authResult, error) in
        if let error = error {
            print("Failed to Login Google user to Firebase db", error)
            return
        }

        print("Successfull Login")
    }

    guard let mainTabBarController = UIApplication.shared.keyWindow?.rootViewController as? MainTabBarController else { return }

    mainTabBarController.setupViewControllers()

    self.dismiss(animated: true, completion: nil)
}

var window: UIWindow?

最后一点注意:我只使用swift代码做这个项目,没有故事板部分。首先,你不必将它保存在AppDelegate中,你可以将它添加到任何vc中,只需与委托保持一致,如

class LoginVC: UIViewController, GIDSignInDelegate,GIDSignInUIDelegate {


其次,您必须在
Auth.Auth().signandRetrieveData内部进行移动,因为它是异步的

Auth.auth().signInAndRetrieveData(with: credential) { (authResult, error) in
    if let error = error {
        print("Failed to Login Google user to Firebase db", error)
        return
    } 
     print("Successfull Login") 
     let mainTab = mainTabBarController() 
     mainTab.setupViewControllers()
     self.window?.rootViewController = mainTab
}
AppDelegate
中使用

self.window?.rootViewController = mainTab
在任何vc使用中

(UIApplication.shared.delegate as! AppDelegate).window?.rootViewController = mainTab
(UIApplication.shared.delegate as! AppDelegate).window?.rootViewController = mainTab