Where to save files in iOS 5 applications?

2019-05-22 13:05发布

I heard that apple changed some things, concerning the memory management in iOS 5. So where is the best place, to save app data and files in my new iOS 5 application - without losing data?

3条回答
等我变得足够好
2楼-- · 2019-05-22 13:41

I believe you can save data in either Caches or Documents or tmp directories. The former 2 are actually backed by (i.e. data backup) by iTunes automatically when you connect to it.

For example this code accesses the Caches directory -

NSArray *cachesDirList = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cacheDir = [cachesDirList objectAtIndex:0];

You can experiment with either Documents or tmp in similar fashion. Hope this helps...

查看更多
Viruses.
3楼-- · 2019-05-22 13:49

To add to what @Srikar have said, only save data in Caches if you can regenerate it. It has been found that when the device is running short on memory it clears off the app's cache directory. This has been confirmed on various blog post and developers.

查看更多
乱世女痞
4楼-- · 2019-05-22 13:58

if it's iOS5 only consider using iCloud. For local storage iOS sandbox hasn't changed much, NSDocumentsDirectory (which is backed up to iTunes).

查看更多
登录 后发表回答