I have an application where there are two kinds of users. So I check if a user is logged in or not. If the user is logged in, I see what kind of user it is. Else, I go to the log in page. However, the application crashes, and I think it is because the Firebase requests takes too long to request.
Here is the code:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
if (FIRAuth.auth()?.currentUser) != nil {
print("user is logged in...")
var ref: FIRDatabaseReference!
ref = FIRDatabase.database().reference()
let userID = FIRAuth.auth()?.currentUser?.uid
ref.child("patients").child(userID!).observe(.value, with: { (snapshot) in
if snapshot.exists(){
print("ahhhhh")
self.window?.rootViewController = UINavigationController(rootViewController: PatientController())
}
else {
print("doesn't exist...")
self.window?.rootViewController = UINavigationController(rootViewController: PhysicianController())
}
})
}
else{
print("hello?3")
window?.rootViewController = UINavigationController(rootViewController: LoginController())
}
return true
}
Any Help will be greatly appreciated!