开发者

Write simple data to iphone sandbox?

开发者 https://www.devze.com 2022-12-23 04:38 出处:网络
I want to write a small bit of data from my app to the iphone so I can load i开发者_StackOverflowt when the app next starts. I am going to write the data using NSCoding, but I don\'t know what I shoul

I want to write a small bit of data from my app to the iphone so I can load i开发者_StackOverflowt when the app next starts. I am going to write the data using NSCoding, but I don't know what I should be specifying as a path. I understand I would write the data to the application sandbox, just not sure how to specify that.

gary


Several paths are available: Documents folder - its contents persist between application launches and is backuped by iTunes. To get path to it use:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileInDoc = [documentsDirectory stringByAppendingPathComponent:fileName];

Caches folder - almost same, but contents is not backuped by iTunes.

For more information see Commonly Used Directories and Getting Paths to Application Directories in "iPhone Application Programming Guide"

0

精彩评论

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

关注公众号