好的,我想跟踪我的iPhone应用程序的启动次数。 对于我们最活跃的用户,我将使用此号码作为“排行榜”。 我认为代码需要在-DidBecomeActive方法中,因为在iOS4中,应用程序可能会在后台保留一段时间。
现在我知道它可能是微不足道的,我只是让它变得比必要的更难,但我不能为我的生活弄清楚如何做到这一点! 每次启动应用程序或从后台返回应用程序时,只需要启动号码加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.
最满意答案
使用NSUserDefaults :
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; NSInteger launchCount = [prefs integerForKey:@"launchCount"]; launchCount++; NSLog(@"Application has been launched %d times", launchCount); [prefs setInteger:launchCount forKey:@"launchCount"];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"];更多推荐
发布评论