开发者

Storing some values for later use - iPhone application

开发者 https://www.devze.com 2023-01-31 01:36 出处:网络
I have an iPhone application that does an action. Let\'s call it X. I\'d like to have开发者_JAVA技巧 a pop up that asks the user if they want to rate my application after they have performed action X

I have an iPhone application that does an action. Let's call it X. I'd like to have开发者_JAVA技巧 a pop up that asks the user if they want to rate my application after they have performed action X ten times. How can I keep track of this? Meaning, if they close the application the value will still be available. Do I need to keep a text file and update the value and write to a file each time or is there an easier way?


Use NSUserDefaults.

You can do something like this to retrieve the value:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
int timesOpened = [defaults integerForKey:@"timesOpened"];

To save a value you do:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
int timesOpened = [defaults integerForKey:@"timesOpened"];
[defaults setInteger:(timesOpened + 1) forKey:@"timesOpened"];
[defaults synchronize];

See here for more information


Why not just use L0SolicitReview. It does this, only a little bit different (still in line with what you described, just a few extra constraints). Best of all, it's done for you.


Another option is, use SQLite3 which is already included in iOS SDK. This works for people who are more familiar with SQL than Cocoa.

0

精彩评论

暂无评论...
验证码 换一张
取 消