开发者

Saving player's data from iPhone to iPhone

I have an iPhone game, where, dunno, the player has like 3000 gold. Sweet.

Then his iPhone had some badass spontaneous combustion.

The player gets a new iPhone, but logically the game will r开发者_如何学运维eset him to 0 gold. What method do you recommend me for saving such important data? Also, the data I might want to store can be a bit larger (loads of arrays containing important player stuff).

Thank you.


Store the info you need in the application support directory for your app.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *appSupportDirectory = [paths objectAtIndex:0];

You can write your arrays out to a plist file in this directory. Then if they choose to restore from a backup from the destroyed phone and they have made sure to sync their phone before they let it combust they will get their gold back.

Keep in mind that one could use the restore from backup feature to get to a previous amount of gold so you want to store their purchases and progress in a similar manor.

Also, depending on what you mean by "loads of arrays" you should probably consider using core data instead of plist files. Your code will scale much better. You can store your database in the same directory to get the same backup behavior.


Recently some apps tried to provide an option to sync data with dropbox. There must be some easy code snippets to do that. You could give an option to sync the save game data with Dropbox.


You can use GameCenter or OpenFeint or both. In fact, most devs use both.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜