Ios 成功登录时执行检查-Firebase/Swift

Ios 成功登录时执行检查-Firebase/Swift,ios,swift,firebase,Ios,Swift,Firebase,我想做的是在成功通过Firebase身份验证后转到适当的视图控制器。因此,当用户单击“登录”时,它会检查凭据是否正确,如果正确,它将转到我的下一个视图控制器。这就是我所拥有的,我不断得到错误“线程1:信号SIGABRT” 这是我的viewController.swift import UIKit import Firebase import GoogleSignIn class ViewController: UIViewController, GIDSignInUIDelegate, GI

我想做的是在成功通过Firebase身份验证后转到适当的视图控制器。因此,当用户单击“登录”时,它会检查凭据是否正确,如果正确,它将转到我的下一个视图控制器。这就是我所拥有的,我不断得到错误“线程1:信号SIGABRT”

这是我的viewController.swift

import UIKit
import Firebase
import GoogleSignIn


class ViewController: UIViewController, GIDSignInUIDelegate, GIDSignInDelegate {
@IBOutlet weak var txtPassword: UITextField!
@IBOutlet weak var txtEmail: UITextField!
@IBOutlet weak var txtAuthStatus: UILabel!


override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
    GIDSignIn.sharedInstance().delegate = self
    GIDSignIn.sharedInstance().uiDelegate = self

    if let user = Auth.auth().currentUser {
        self.txtAuthStatus.text = "Signed in as " + user.email!;
    }
    else {
        self.txtAuthStatus.text = "";
    }

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

    func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) {
        if let error = error {
            print(error.localizedDescription)
            return
        }
        try! Auth.auth().signOut()
    }

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

    let authentication = user.authentication
    let credential = GoogleAuthProvider.credential(withIDToken: (authentication?.idToken)!, accessToken: (authentication?.accessToken)!)

    Auth.auth().signIn(with: credential, completion: { (user, error) in
        if error != nil {
            print(error?.localizedDescription as Any)
            return
        }
        print("User logged in with Google")
    })
}




@IBAction func btnCreateUser(_ sender: Any) {
    if let email:String = txtEmail.text, let pass:String = txtPassword.text {
        Auth.auth().createUser(withEmail: email, password: pass) {
            (user, error) in
            if let error = error {
                let errCode = AuthErrorCode(rawValue: error._code);
                if (errCode == .emailAlreadyInUse) {
                    self.txtAuthStatus.text = "Error: user already exists";
                } else {

                    self.txtAuthStatus.text = error.localizedDescription;
                }
            }
            if let user = user {
                self.txtAuthStatus.text = "Signed in as " + user.email!
                self.txtEmail.text = nil;
                self.txtPassword.text = nil;

            }
        }
    }
}
@IBAction func btnSignIn(_ sender: Any) {
    if let email:String = txtEmail.text, let pass:String = txtPassword.text {
        Auth.auth().signIn(withEmail: email, password: pass) {
            (user, error) in
            if let error = error {
                let errCode = AuthErrorCode(rawValue: error._code);
                if (errCode == .userNotFound) {
                    self.txtAuthStatus.text = "Error: user not found";
                }
                else if (errCode == .wrongPassword) {
                    self.txtAuthStatus.text = "Error: wrong password";
                }
                else if (errCode == .userDisabled) {
                    self.txtAuthStatus.text = "Error: user account disabled";
                }
                else {
                    self.txtAuthStatus.text = error.localizedDescription;
                }
            }
            if let user = user {
                self.txtAuthStatus.text = "Signed in as " + user.email!
                self.txtEmail.text = nil;
                self.txtPassword.text = nil;
                self.performSegue(withIdentifier: "signin", sender: self)

            }
        }
    }
}
@IBAction func btnSignOut(_ sender: Any) {
    try! Auth.auth().signOut();
    self.txtAuthStatus.text = "Signed out";
}

}
这是我的AppDelegate.swift

import UIKit
import Firebase
import GoogleSignIn

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    FirebaseApp.configure()
    return true
}
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any])
    -> Bool {
        return GIDSignIn.sharedInstance().handle(url,
                                                 sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
                                                 annotation: [:])
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
    return GIDSignIn.sharedInstance().handle(url,
                                             sourceApplication: sourceApplication,
                                             annotation: annotation)
}

func applicationWillResignActive(_ application: UIApplication) {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}


我想移动的视图控制器和它的标识符之间有一段距离,标识符是“signin”

我的问题是,当我推到下一个视图控制器时,它不再有电子邮件和密码的文本字段。通过将登录功能切换到另一个.swift文件,并将其视图控制器切换到另一个类,它不再寻找正在加载的对象,现在它可以完美地工作

那么我们可以复制的具体问题是什么?谢谢你的代码转储,但是这对我们帮助你有什么帮助呢?你有调试问题吗?该问题是否与分段有关?(这在你的标题中,所以我猜是这样。但似乎它可能来自几个地方。那么你为什么相信它来自于那个地方?请,具体细节很重要!)是的,当我尝试调用self.performsgue(带有标识符:“sign”,发送者:self)时,问题与程序的分段和崩溃有关。登录本身工作正常,应用程序的其余部分也工作正常。我只需要解决一种方法,使我能够通过Firebase进行身份验证后继续。我的当前解决方案导致“在展开时意外发现零”错误。在viewDidLoad中,在带有self.txtAuthStatus.text=“以“+user.email!”的行中!;然后你需要找出什么是
nil
!可能是用户没有电子邮件,或者您的Friebase呼叫没有正确返回电子邮件?再次感谢您的代码转储,但这不是一个修复代码的站点。在打开包装时,有几十个与查找零相关的问题。我的第一个想法——好的,第二个,因为我已经给了你一个检查的地方——是检查你所有的解包代码,特别是给出
nil
错误的那一行,找到什么是nil并修复它。(虽然不想太苛刻,但这是一个质量很差的问题。)