I've got around a couple of K of game data, mostly top scores per level, which levels are unlocked, etc. Stuff that is only updated at the end of play and it would be best to keep saved across play sessions.
What is the best way of doing this? I'm sure you can just read/write a file in the usual way, but that would then be inside your package. Am I right in assuming if I were to push out an update the existing package would just get nuked and I would then lose those files?
If so, what is the recommended alternative? I just want to dump a couple of K of binary blob someplace where it will persist.
iOS and persisting game state
Re: iOS and persisting game state
The Documents folder of your app persists between updates. Here's what I use:
NSString* fullPathFilename(NSString* file)
{
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* result = [[[NSString alloc] initWithFormat:@"%@/%@", [paths objectAtIndex:0], file] autorelease];
return result;
}
Re: iOS and persisting game state
As has been said, use an SQLite database or property list in 'Documents', or use NSUserDefaults.
*never*, *ever*, *ever*, try to store data in your application bundle. If you try to do that, the ghost of Steve Jobs will come round and break your knees.
*never*, *ever*, *ever*, try to store data in your application bundle. If you try to do that, the ghost of Steve Jobs will come round and break your knees.
"massive retard™", "full of shit™", "tiny bitch™", "retarted™", "a bit of a one trick pony™", "petty™", "simple minded idealistic twat™", "miserable humourless fucker™"
Re: iOS and persisting game state
NSUserDefaults if the data is small is the right way to do this. Also on ios5 you will almost get iCloud support for free by doing that.
- korruptor
- Baaaaaa!

- Posts: 4291
- Joined: Sun Sep 22, 2002 10:35 am 0
- Location: Under The Northern Lights
- Contact:
Re: iOS and persisting game state
You can put quite large lumps of data in NSUserDefaults. That's what I use as well.
"Don't go into a trance boys..." :: DJ Mixes
Re: iOS and persisting game state
Be careful storing too much data in NSDocumentDirectory. All that now goes to the iCloud and if there's too much in there, the nice people at Apple with reject your App unceremoniously.
Small amounts they are ok with....
We were told to use NSCacheDirectory instead for big saves
Small amounts they are ok with....
We were told to use NSCacheDirectory instead for big saves
- sack
- Baaaaaaa!

- Posts: 7077
- Joined: Fri May 10, 2002 4:13 pm 0
- XBL Gamertag: evilgopher
- PSN: sixFiveOhTwo
- Location: Rijswijk, The Netherlands
- Contact:
Re: iOS and persisting game state
Well I'm thinking of less than 1K. Size-wise it's nothing, but given that small file represents all of your progress made so far you'd miss it 
I'd rather write a file to an acceptable folder to be honest, because I'm trying to keep as much of the code common between iOS/android/windows as possible.
I'd rather write a file to an acceptable folder to be honest, because I'm trying to keep as much of the code common between iOS/android/windows as possible.



