Reputation: 447
On Windows, we can write values into registry to know that
but how can I know if my application is the first time it runs on a mac? I need to perform some initialization task.
Thanks
Upvotes: 3
Views: 2366
Reputation: 21736
You are looking for the class NSUserDefaults
(see Apple Documentation)
For example:
#define kAlreadyBeenLaunched @"AlreadyBeenLaunched"
if (! [[NSUserDefaults standardUserDefaults] boolForKey:kAlreadyBeenLaunched]) {
// This is our very first launch
// Setting userDefaults for next time
[[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithBool:YES] forKey:kAlreadyBeenLaunched];
// Do your first time stuff
//<##>
}
You will use the same class to save and retrieve user preferences.
This values will be saved in ~/Library/Preferences/<your_bundle_id>.plist
. This is useful to know for debugging, by looking at the file, but you should not rely on this implementation detail in your code.
Upvotes: 7
Reputation: 3389
There are tons of other people that already asked this.
I guess this one is the most helpful. iPhone: How do I detect when an app is launched for the first time?
Mention: It's working exactly the same way as on the iOS system.
Upvotes: 1