So, I'm working on a new application, and I use Firebase to manage all the backend files with user inputs, etc., I created a login / registration screen for users when loading the application. What I'm trying to do is load HomeScreenVC, if the user is already logged in, and if the user is not, then they will be sent to login / register vc.
I kind of work in the sense that it works if the user is already currentUser, but the problem I'm having is that if the user has never downloaded the application, it crashes because it cannot detect currentUser.
My code that I have in AppDelegate is:
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 }
This is the error I get: here
Any help would be great! I am using the latest version of Firebase and Swift 2.
ios login swift firebase firebase-authentication
Konsy
source share