Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch Count on iPhone App

Ok I want to keep track of how many times my iPhone App has been launched. I will be using this number for a "leader board" for our most active user. I figured the code needs to be in the -DidBecomeActive method being that in iOS4 the app may remain in the background for sometime.

Now I know it's probably trivial and i'm just making it more difficult than necessary but I can't for the life of me figure out how to do this! Just want the launch number to increase by 1 every time the app is launched or returned from the background.

Any help is greatly appreciated.

like image 455
Adam Nieto Avatar asked Dec 12 '25 07:12

Adam Nieto


1 Answers

Use NSUserDefaults:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSInteger launchCount = [prefs integerForKey:@"launchCount"];
launchCount++;
NSLog(@"Application has been launched %d times", launchCount);
[prefs setInteger:launchCount  forKey:@"launchCount"];
like image 73
Brock Woolf Avatar answered Dec 15 '25 04:12

Brock Woolf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!