ios - 火力地堡 + swift : Bypass User Login Screen

标签 ios swift authentication firebase 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
}

这是我得到的错误:here

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

最佳答案

你在该行强制解包 nil,导致崩溃。从 FIRAuth.auth()?.currentUser!

中删除 !

关于ios - 火力地堡 + swift : Bypass User Login Screen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38191190/

相关文章:

swift - 无法转换类型错误 Swift 的值

swift if let statement with as?,但为什么要用问号?

asp.net-mvc-3 - 在 MVC 3 中持久化用户数据

ios - NSDictionary EXC_BAD_ACCESS

ios - 在执行dispatch_semaphore_wait(sem,DISPATCH_TIME_FOREVER)之后,再也不会收到回调

html - 在 ios swift 中加载 html 字符串,UIWebView 除外

java - Windows 到 Linux 文件传输上的 JCifs 登录失败

objective-c - 带有 LLDB 的 Xcode 4.3 中的奇怪错误消息

ios - 在我的应用程序开始时使用 6 个图像为应用程序创建入门教程 - 停留在实际创建图像上

asp.net - 将 ASP.NET MVC5 身份验证添加到现有项目