[ios2] iOS 5的文件存储策略应对【转】
2013-05-16 09:04
337 查看
苹果在iOS 5系统时,对app的文件存储提出了新的要求。从它的guildline来看,是推荐开发者尽量把app生成的文件放在Caches目录下的。原文如下:
Only user-generated data or that cannot otherwise be recreated by your application, should be stored in the /Documents directory and rest should be stored to /Library/Caches directory。
如果对此置之不理,继续把应用生成的文件放在Documents目录下,那么这些文件会被备份到iTunes或者iCloud。如果这些文件很大,那么用户可能需要为了同步消耗不少流量,然后苹果可能会因此拒绝你的应用上架,这是一个悲剧。
如果开发者照Apple说的干,把应用生成的文件放在Caches目录下,那么苹果不会拒绝你的应用,很happy。但是iOS 5会在磁盘空间紧张的时候删除Caches目录下的文件,这对用户来说可能是一个更大的悲剧。
继续把文件存储在Documents目录下,但是标记这些文件为不需要备份。详情请参考 technote (QA1719)
原文如下:
Q: My app has a number of files that need to be stored on the device permanently for my app to function properly offline. However, those files do not contain user data and don’t need to be backed up. How should I store those files in iOS 5?
A: Starting in iOS 5.0.1 a new “do not back up” file attribute has been introduced allowing developers to clearly specify which files should be backed up, which files are local caches only and subject to purge, and which files should not be backed up but should also not be purged. In addition, setting this attribute on a folder will prevent the folder and all of its contents from being backed up.
Only user-generated data or that cannot otherwise be recreated by your application, should be stored in the /Documents directory and rest should be stored to /Library/Caches directory。
照做会怎么样?
如果这么做的话,会出现两种情况如果对此置之不理,继续把应用生成的文件放在Documents目录下,那么这些文件会被备份到iTunes或者iCloud。如果这些文件很大,那么用户可能需要为了同步消耗不少流量,然后苹果可能会因此拒绝你的应用上架,这是一个悲剧。
如果开发者照Apple说的干,把应用生成的文件放在Caches目录下,那么苹果不会拒绝你的应用,很happy。但是iOS 5会在磁盘空间紧张的时候删除Caches目录下的文件,这对用户来说可能是一个更大的悲剧。
如何应对新的文件存储策略?
开发者在这时陷入了两难的境地,但是到了iOS 5.0.1的时候,开发者多了第三种选择:继续把文件存储在Documents目录下,但是标记这些文件为不需要备份。详情请参考 technote (QA1719)
原文如下:
Q: My app has a number of files that need to be stored on the device permanently for my app to function properly offline. However, those files do not contain user data and don’t need to be backed up. How should I store those files in iOS 5?
A: Starting in iOS 5.0.1 a new “do not back up” file attribute has been introduced allowing developers to clearly specify which files should be backed up, which files are local caches only and subject to purge, and which files should not be backed up but should also not be purged. In addition, setting this attribute on a folder will prevent the folder and all of its contents from being backed up.
代码示例
给文件加上”do not back up”属性的代码如下,需要注意这个是iOS 5.0.1才有效,低于这个版本就别费劲了。#include<sys/xattr.h>-(BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL {constchar* filePath =[[URL path] fileSystemRepresentation];constchar* attrName ="com.apple.MobileBackup";u_int8_t attrValue =1;int result = setxattr(filePath, attrName,&attrValue,sizeof(attrValue),0,0);return result ==0;}
相关文章推荐
- [ios2] iOS 5的文件存储策略应对【转】
- iOS 5的文件存储策略应对
- iOS 5的文件存储策略应对
- Documents下存储文件被拒解决方法(文件存储策略应对)
- ios大文件存储
- ios 文件存储的五种方式
- iOS音频文件存储
- iOS开发,图片制作水印,图片裁剪,图片条纹背景,图片截图,以及将图片成文件存储。基于Quartz2D技术
- [ios2]苹果iOS 5限制应用本地存储问题 【转】
- iOS应用程序安全(20)-本地数据存储及其安全性(NSUserDefaults, CoreData, Sqlite, Plist 文件)
- ios 字符串,字典,数组存储到本地文件
- 组策略之(4)-------可移动存储的文件保护(只读设置)
- iOS NSURL、NSBundle获取文件,解析文件,存储文件等操作
- iOS音频文件存储
- ios 文件存储 iOS Data Storage Guidelines 和 "do not back up"文件属性
- ios客户端学习-文档存储/路径处理/文件操作
- iOS 数据存储 plist文件存储
- iOS 录视频,相册选择视频,视频压缩,存储本地文件,播放,上传
- IOS文件系统和数据的永久性存储
- IOS数据存储之文件沙盒存储