sterling archer
sterling archer

Reputation: 334

How to make a screen show only on initial launch

I'm trying to make the intro screens for my app - namely the terms of service screen that all users have to agree to the 1st time they download and run the app. obviously, once the users agree, i dont want to show them it again every time they log on the app. what is the best way to go about doing this? I've been reading about NSUserDefaults, but am stuck pretty much after that.

Upvotes: 0

Views: 1067

Answers (2)

Nati Lara-Diaz
Nati Lara-Diaz

Reputation: 2202

Play with this piece of code in the AppDelegate Class

let launchedBefore = NSUserDefaults.standardUserDefaults().boolForKey("launchedBefore")
    if launchedBefore  {
        print("Not first launch.")
    }
    else {
        print("First launch, setting NSUserDefault.")
        NSUserDefaults.standardUserDefaults().setBool(true, forKey: "launchedBefore")
    }

Upvotes: 2

Joshua Sullivan
Joshua Sullivan

Reputation: 1139

In your AppDelegate or whichever class needs to check for first-run status:

Bool isFirstRun = !NSUserDefaults.standardUserDefaults().boolForKey("kAppPreviousLaunchKey")
NSUserDefaults.standardUserDefaults().setBool(true, forKey:"kAppPreviousLaunchKey")
if isFirstRun {
    // React here
}

Upvotes: 3

Related Questions