如何防止文件备份到iCloud和iTunes
2015-09-23 22:26
260 查看
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?
Starting in iOS 5.1, apps can use either NSURLIsExcludedFromBackupKey or kCFURLIsExcludedFromBackupKey file system properties to exclude files and directories from backups. Apps that need to exclude a large number of files can exclude them by creating their own sub-directory and marking that directory as excluded. Apps should create their own directories for exclusion, rather than excluding the system defined directories. Either of these APIs is preferred over the older, deprecated approach of directly setting an extended attribute. All apps running on iOS 5.1 and later should use these APIs to exclude data from backups.
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?
Starting in iOS 5.1, apps can use either NSURLIsExcludedFromBackupKey or kCFURLIsExcludedFromBackupKey file system properties to exclude files and directories from backups. Apps that need to exclude a large number of files can exclude them by creating their own sub-directory and marking that directory as excluded. Apps should create their own directories for exclusion, rather than excluding the system defined directories. Either of these APIs is preferred over the older, deprecated approach of directly setting an extended attribute. All apps running on iOS 5.1 and later should use these APIs to exclude data from backups.
- (BOOL)addSkipBackupAttributeToItemAtPath:(NSString *) filePathString { NSURL* URL= [NSURL fileURLWithPath: filePathString]; 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; }
相关文章推荐
- libcurl.a + sqlcipher 渊源
- 0916词法分析
- 将函数返回参数转化为二进制并统计1的个数
- 【一些事晚报】中国IT人员平均年薪27万元全球排名13?呵呵。。
- 系统实现邮件、拨号、SMS、浏览器的调用
- 流程控制(学习C语言的转折点)
- 【面试】如何找到迷宫出口
- hihocoder 1228 Mission Impossible 6
- uva 1327 - King's Quest(强联通)
- UVA110模拟出Pascal的8个数字的排序代码插入式递归
- HDU 5437 Alisha’s Party(优先队列)(2015网络赛长春站)
- HDU 5458(Stability-LCT维护连通图2点间割边个数)
- 创建线程的第三种方法-callable futureTask
- process mining(data source+d)+算法第二讲
- 欢迎使用CSDN-markdown编辑器
- Java并发知识点总结(上)
- [cyber security][php]pfSense目录遍历漏洞分析
- 将链表中的所有元素为奇数的节点移到元素为偶数节点的前面,并保证奇数之间顺序不变,偶数之间顺序不变。
- 数据挖掘十大算法
- MySQL 新增用户 权限分配 远程登录