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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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
}
回答2:
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")
}