Launch an account on an iPhone application

Ok, I want to keep track of how many times my iPhone app has been launched. I will use this number for the "leader" for our most active user. I figured the code should be in the -DidBecomeActive method, since in iOS4 the application may remain in the background for a while.

Now I know that this is probably trivial, and I just make it harder than necessary, but I can’t let my life determine how to do it! I just want the launch number to increase by 1 every time the application starts or returns from the background.

Any help is appreciated.

+3
source share
1 answer

NSUserDefaults:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSInteger launchCount = [prefs integerForKey:@"launchCount"];
launchCount++;
NSLog(@"Application has been launched %d times", launchCount);
[prefs setInteger:launchCount  forKey:@"launchCount"];
+7

Source: https://habr.com/ru/post/1760230/


All Articles