CodeGuy
CodeGuy

Reputation: 28905

Storing some values for later use - iPhone application

I have an iPhone application that does an action. Let's call it X. I'd like to have 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?

Upvotes: 0

Views: 94

Answers (3)

Di Wu
Di Wu

Reputation: 6448

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

Upvotes: 0

jer
jer

Reputation: 20236

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.

Upvotes: 2

fabian789
fabian789

Reputation: 8412

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

Upvotes: 2

Related Questions