简体   繁体   中英

Calling Terms and Conditions in Swift / Xcode on first load

I have set up an application with two ViewControllers:

1) Terms and Conditions screen

2) General welcome screen.

I want my app to show the Terms and Conditions ViewController on startup as long as the user hasn't accepted the terms yet.

Once accepted, the general welcome screen should be the first loaded ViewController in the cycle. How can I manage this?

After you view the terms save a bool value in userDefaults say it's termsViewed and check it in didFinishLaunchingWithOptions to trigger direct navigate to welcome screen

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {


    if UserDefaults.standard.bool(forKey: "termsViewed")
    { 
        let stor = UIStoryboard.init(name: "Main", bundle: nil)

        let welcomeView = stor.instantiateViewController(withIdentifier: "welcomeID")

        let nav = UINavigationController(rootViewController: welcomeView )

        nav.navigationBar.isHidden = true

       self.window?.rootViewController = nav

    }

    return true
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM