How do I detect when an iOS app is launched for the first time?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Xcode: Is there a way to change line spacing (UI L
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
This will not work properly if you want to detect during other places of the code if its first launch. The "applicationWillTerminate" will not work from iOS 4.0 due to multitasking. this link provides a good solution: http://mobiledevblog.metalcompass.com/?p=43
Pretty much what Marc and Chris said, though I prefer to change the value when the app quits in case there're multiple areas of the application that need to know about it. In code:
Save it as a user preference, eg had_first_launch, set to true on startup, it will only be false on the first time...
You can set a boolean value in the user defaults to do this. Set the key to false when you call
registerDefaults:
, and then set it to true change it to true after you've shown your initial help screen or whatever you need to do.If you have a persistent data file that's always saved after the app closes, checking to see if it exists would be another way.
This is a really simple shortcut but I found that NSUserDefault key value pairs are always NULL the first time you run an app so
and place this code in the awakeFromNib of the view controller that appears when your application launches. I don't know if any of the other answers work for your problem, but this is the way I solved it.
I realize this question is quite old, but I used it to come up with one method of detecting the first startup after a "fresh install" (vs. first startup after an upgrade/downgrade) and thought I'd share the code here for future viewers in case it's helpful.