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 apprec开发者_如何学Goiated.
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"];
精彩评论