Firebase + Swift:绕过用户登录屏幕

Kon*_*nsy 8 login ios firebase swift firebase-authentication

所以我正在开发一个新的应用程序,我正在使用Firebase管理所有后端的东西,用户登录等,我已经为用户加载应用程序时创建了一个登录/注册屏幕.我正在尝试做的是加载HomeScreenVC,如果用户已经登录,如果用户不是,那么他们将被定向到登录/注册vc.

如果用户已经是currentUser,我可以使用它,但我遇到的问题是,如果用户从未加载应用程序,那么它会崩溃,因为它无法检测currentUser.

我在AppDelegate中的代码是:

var window: UIWindow?
var storyboard: UIStoryboard?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    FIRApp.configure()

    self.storyboard =  UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
    let currentUser = FIRAuth.auth()?.currentUser!
    if currentUser != nil
    {
        self.window?.rootViewController = self.storyboard?.instantiateViewControllerWithIdentifier("tabVC")
    }
    else
    {
        self.window?.rootViewController = self.storyboard?.instantiateViewControllerWithIdentifier("loginScreen")
    }
    return true
}
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:这里

任何帮助都会很棒!我正在使用最新版本的Firebase和Swift 2.

sta*_*kri 7

你是在那条线上展开nil,导致崩溃.取出!FIRAuth.auth()?.currentUser!