Vitya Shurapov Vitya Shurapov - 1 year ago 83
Swift Question

How to skip the login scene and start straight from the next if you are already authorized?

What is the best place to check if the user is already logged-in and how to realize the transition to the first app scene skipping the login viewController?

Answer Source

I do this in my AppDelegate. In my main storyboard, my initial view controller assumes that my user is logged in. Thus, in my AppDelegate I do the following to decide whether I need to show the login screen:

// Show login view if not currently logged in
if (!currentUser){

    let sb = UIStoryboard(name: MainStoryboardId, bundle: Bundle.main)
    let vc = sb.instantiateViewController(withIdentifier: loginViewControllerId)

    vc.modalTransitionStyle = .crossDissolve
    window.rootViewController = vc

PS, just converted code from Objective-C... it's untested.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download