IOS Data Storage

来源:互联网 发布:淘宝新店引流方法 编辑:程序博客网 时间:2024/04/27 13:41

    应用又被拒绝了,原因是IOS Data Storage  

为了区分清楚sandbox里边各个目录的作用,我去看了下apple文档,sandbox目录介绍

总结下:

Documents:存放用户产生的数据,比如用户下载的视频图书,浏览记录等。但是对于位于Documents中可在生成或可重新下载的资源,必须标记为不能通过iTunes恢复的类型(NSURLIsExcludedFromBackupKey)(意思是说文件太大了,又是个动态的,不需要备份)。翻译的比较挫,看下官方的原话,自己体会下:

Remember that files in Documents/ and Application Support/ are backed up by default. You can exclude files from the backup by calling -[NSURL setResourceValue:forKey:error:] using the NSURLIsExcludedFromBackupKey key. Any file that can be re-created or downloaded must be excluded from the backup. This is particularly important for large media files. If your application downloads video or audio files, make sure they are not included in the backup.

具体方法:

//标记文件夹不可从iTunes恢复

            [[NSURLURLWithString:resource]setResourceValue:@(YES)

                                                                                   forKey:NSURLIsExcludedFromBackupKey

                                                        error:nil];



Library/Preferences:我们不需要自己创建文件进去,这个目录一般是程序使用NSUserDefaults存储数据的地方。支持iTunes恢复。


Library/Caches: 这个目录可以用来存储任何文件,包括用户的数据。IOS2.2之后caches就不在支持iTunes恢复,并且会在iTunes恢复时被清空,IOS5之后系统会在硬盘紧张时清空该目录。所以用来存储用户数据需要谨慎,最好是放到Documents。  


Tmp: 在程序运行的时候可用来存放临时文件,文件不再需要时需要自己手动移除,当然系统在程序没有运行时也会定期清空,不支持iTunes恢复。



PS:用到的同学请点个赞吧



1 0