views:

47

answers:

1

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.

+4  A: 

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"];
Brock Woolf
thanks that worked perfectly!
Adam Nieto