所以我正在开发一个新的应用程序,我正在使用 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/