I have made an application for my client by keeping target iOS as 4.
But since the application still not submitted to Apple store, my client is planning to upgrade it for iOS 5.0.

For this I read the guideline from Apple
and found that "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"

In my application, I am using server model of in-app purchase for
non-consumable product. For this I am storing all my downloaded data
(which are basically books or magazines) to Documents directory. The
Database is also present in the same directory which contains the
details about the downloaded products.

My question is,
1. Should I have to change my code to store the downloaded data to
Library/Caches directory instead of to the Documents directory?
2. Where should my database file be placed (to Documents or Caches)?

If I put it products in the Caches then I have to change the logic of
retrieval also, since it is considered that if record is present in
database, there is no need change the existence of the file and it
directly opens it when user clicks on the magazine.

Kindly guide me on this issue.
Thanks in advance.

UPDATED:
I am updating this for those who are still not sure about this problem.
Using the guideline of accepted answer, I have implemented this in 2 of
my applications and submitted them to Apple Store. Both were approved in
review.
This may promote that the solution suggested in the accepted answer is correct.

Here are the trade-offs:

  • If you put your files in the Documents directory then they are backed up to iTunes or iCloud but if they are too big and it's possible to download the files again then Apple may reject your app
  • If you put your files in the Cache directory then they won't be backed up and Apple won't reject your app. However, when iOS 5 gets low on space it may delete all the files in there.

However, with iOS 5.0.1 there is a third option:

  • Put files in Documents but flag them so that they are not backed up. There's a technote (QA1719) on how to do this.

I think this is probably the best answer for you.

@font-face { font-family: "Times"; }@font-face { font-family: "宋体"; }@font-face { font-family: "宋体"; }@font-face { font-family: "@宋体"; }@font-face { font-family: "Calibri"; }@font-face { font-family: "Cambria"; }p.MsoNormal, li.MsoNormal, div.MsoNormal { margin: 0cm 0cm 0.0001pt; text-align: justify; font-size: 12pt; font-family: Cambria; }h1 { margin-right: 0cm; margin-left: 0cm; font-size: 24pt; font-family: Times; font-weight: bold; }h2 { margin: 13pt 0cm; text-align: justify; line-height: 173%; page-break-after: avoid; font-size: 16pt; font-family: Calibri; font-weight: bold; }h4 { margin: 14pt 0cm 14.5pt; text-align: justify; line-height: 156%; page-break-after: avoid; font-size: 14pt; font-family: Calibri; font-weight: bold; }a:link, span.MsoHyperlink { color: blue; text-decoration: underline; }a:visited, span.MsoHyperlinkFollowed { color: purple; text-decoration: underline; }p { margin-right: 0cm; margin-left: 0cm; font-size: 10pt; font-family: Times; }code { font-family: Courier; }pre { margin: 0cm 0cm 0.0001pt; font-size: 10pt; font-family: Courier; }span.contenttext { }p.codesample, li.codesample, div.codesample { margin-right: 0cm; margin-left: 0cm; font-size: 10pt; font-family: Times; }span.HTML { font-family: Courier; }.MsoChpDefault { font-family: Cambria; }div.WordSection1 { page: WordSection1; }

How do I prevent files from being backed up to iCloud and iTunes?

Technical Q&A QA1719

How do I prevent files from being backed up to iCloud and iTunes?

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 can I prevent them from being backed up?

A: On iOS, apps are responsible for ensuring that only user data and not application data is backed up to iCloud and iTunes. The exact steps necessary vary between iOS version, so this QA will describe the process for each version of iOS. For more information on exactly what data should or should not be backed up, see the App Backup Best Practices section of the iOS App Programming Guide.

Important: Apps should avoid mingling app data and user data in the same file. Doing so will unnecessarily increase backup sizes and can be considered a violation of the iOS Data Storage Guidelines.

iOS 5.1 and later

Starting in iOS 5.1, apps can use either NSURLIsExcludedFromBackupKey or kCFURLIsExcludedFromBackupKey file properties to exclude files from backups. Either of these APIs is preferred over the older, deprecated approach of directly setting an extended attribute. All apps running on iOS 5.1 should use these APIs to exclude files from backups.

Listing 1  Excluding a File from Backups on iOS 5.1

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);
 
    NSError *error = nil;
    BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]
                                  forKey: NSURLIsExcludedFromBackupKey error: &error];
    if(!success){
        NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
    }
    return success;
}

Back to Top

iOS 5.0.1

If your app must support iOS 5.0.1, you can use the following method to set the "do not back up" extended attribute. Whenever you create a file or folder that should not be backed up, write the data to the file and then call this method, passing in a URL to the file.

Warning: The code that follows has been deprecated and should only be used on iOS 5.0.1 or earlier. When running in iOS 5.1, apps should use the NSURL and CFURL keys described above.

Listing 2  Setting the Extended Attribute on iOS 5.0.1

#import <sys/xattr.h>
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);
 
    const char* filePath = [[URL path] fileSystemRepresentation];
 
    const char* attrName = "com.apple.MobileBackup";
    u_int8_t attrValue = 1;
 
    int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
    return result == 0;
}

Back to Top

iOS 5.0

It is not possible to exclude data from backups on iOS 5.0. If your app must support iOS 5.0, then you will need to store your app data in Caches to avoid that data being backed up. iOS will delete your files from the Caches directory when necessary, so your app will need to degrade gracefully if it's data files are deleted.

Back to Top


Document Revision History

Date

Notes

2012-04-23

Updated for iOS 5.1

2011-11-10

-Fixed critical bug in code snippet.

New document that describes how an app can prevent files from being backed up to iCloud and iTunes.

iOS 5 does not allow to store downloaded data in Documents directory? ios5.0及以后的版本对于下载的文件存储路径有了改变的更多相关文章

  1. unity中的文件存储路径与各平台(Android,iOS)的关系

    原文链接:unity中的文件存储路径与各平台(Android,iOS)的关系 主要是这个问题困扰我了一阵子,所以特写写... unity中的的各种存储方法的对应关系(直接上截图吧) 重点说的是Appl ...

  2. iOS文件存储路径规定

    Storing Your App’s Data Efficiently https://developer.apple.com/icloud/documentation/data-storage/in ...

  3. 发布iOS应用程序到苹果APP STORE完整流程

    参考:http://blog.csdn.net/mad1989/article/details/8167529(xcode APP 打包以及提交apple审核详细流程(新版本更新提交审核)) http ...

  4. iOS应用跳转到App Store评分

    iOS应用跳转到App Store评分 1.跳转到应用评价页 NSString *urlStr = [NSString stringWithFormat:@"itms-apps://itun ...

  5. iOS 5的文件存储策略应对

    苹果在iOS 5系统时,对app的文件存储提出了新的要求.从它的guildline来看,是推荐开发者尽量把app生成的文件放在Caches目录下的.原文如下: Only user-generated ...

  6. IOS中获取各种文件的路径介绍及方法

    IOS中获取各种文件的目录路径的方法 技术交流新QQ群:414971585 iphone沙箱模型的有四个文件夹,分别是什么,永久数据存储一般放在什么位置,得到模拟器的路径的简单方式是什么. docum ...

  7. 一张图教你搞定Mac App Store 应用安装包存储路径

    还在为找不到App Store 更新应用的安装文件发愁吗?是否有过多个人同时需要更新Xcode,都自己下载一次的痛苦经历? 大家都知道通过苹果服务器下载东西,确实难耐!AppStore 甚至都经常提示 ...

  8. IOS文件存储小结

    转自:http://tyragain.lofter.com/post/84706_c1503 首选项设置存储 NSUserDefaults 以及通过它控制的SettingBundle  NSUserD ...

  9. IOS开发--数据持久化篇文件存储(二)

    前言:个人觉得开发人员最大的悲哀莫过于懂得使用却不明白其中的原理.在代码之前我觉得还是有必要简单阐述下相关的一些知识点. 因为文章或深或浅总有适合的人群.若有朋友发现了其中不正确的观点还望多多指出,不 ...

随机推荐

  1. Pre 自动换行和手动换行

    pre { white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre ...

  2. 59、佳博wifi打印机怎么配置

    1.去这里下载配置软件(注意,需要再windows下进行)http://pan.baidu.com/s/1bn1y4FX,并解压安装程序 2.连上wifi打印机的热点,比如说佳博打印机的默认为Gpri ...

  3. 对CRC32的小结加上bugku一道题目:好多压缩包

    CRC32就是校验值,一般来说不同的文件校验值不一样,所以我们可以挨个爆破,当然这是在文件比较小的时候.下面是几种情形. 1. 我新建了一个flag.txt文档,里面是我的生日20180818 然后我 ...

  4. MySQL出现错误1045,用户无法连接

    1.root用户可以登陆进去 假设新建了个sqlin用户,但是无法用此用户连接MySQL 这个时候root用户可以登录吧,root用户登录进去,重新修改该用户的密码,执行语句 use mysql; u ...

  5. Mac Xnip 截图软件快捷键设置

    点击 Shortcut 后输入你需要的截图快捷键

  6. LeetCode668马在棋盘上的概率

    已知一个 NxN 的国际象棋棋盘,棋盘的行号和列号都是从 0 开始.即最左上角的格子记为 (0, 0),最右下角的记为 (N-1, N-1). 现有一个 “马”(也译作 “骑士”)位于 (r, c)  ...

  7. Leetcode 643.子数组最大平均数I

    子数组最大平均数I 给定 n 个整数,找出平均数最大且长度为 k 的连续子数组,并输出该最大平均数. 示例 1: 输入: [1,12,-5,-6,50,3], k = 4 输出: 12.75 解释: ...

  8. vlc无法播放.flv视频文件

    解决方法:https://videoconverter.wondershare.com/vlc/flv-not-displaying-video-vlc-media-player.html. 在pre ...

  9. [python][django学习篇][11]后台admin用户登录博客,添加文章---这一章和博客首页设计没有关系

    1 如果没有创建超级管理员账号,先要创建python manage.py createsuperuser 2 在admin后台注册模型(如果没有这一步,登录http://127.0.0.1:8000/ ...

  10. linux服务器上设置多主机头,设置多web站点

    假设VPS的IP是58.130.17.168,有两个域名指向该IP,分别是domain1.com, domain2.com, 修改/etc/httpd/conf/httpd.conf,在文件的最后加入 ...