Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect first launch of iOS app [duplicate]

Tags:

ios

swift

I am trying to find a way in Swift to detect the first launch.

like image 827
Julian Stellaard Avatar asked Nov 29 '14 23:11

Julian Stellaard


1 Answers

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") } 
like image 151
Jon Shier Avatar answered Oct 23 '22 04:10

Jon Shier