本文介绍了检测首次推出的iOS应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在Swift中找到一种方法来检测第一次启动。
I am trying to find a way in Swift to detect the first launch.
推荐答案
通常你会写一个值给NSUserDefaults表示应用程序之前已启动。
Typically you would write a value to NSUserDefaults to indicate that an app has launched before.
let launchedBefore = NSUserDefaults.standardUserDefaults().boolForKey("launchedBefore")
if launchedBefore {
print("Not first launch.")
}
else {
print("First launch, setting NSUserDefault.")
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "launchedBefore")
}
UPDATE - Swift 3
let launchedBefore = UserDefaults.standard.bool(forKey: "launchedBefore")
if launchedBefore {
print("Not first launch.")
} else {
print("First launch, setting UserDefault.")
UserDefaults.standard.set(true, forKey: "launchedBefore")
}
这篇关于检测首次推出的iOS应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!