iPhone开发:如何阻止文件被iTunes和iCloud同步 How do I prevent files from being backed up to iCloud and iTunes?
2012-03-23 11:28
896 查看
先阅读官方说明:
https://developer.apple.com/library/ios/#qa/qa1719/_index.html
使用方法:
#import “sys/xattr.h”
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
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;
}
- (void)addSkipBackupAttributeToPath:(NSString*)path {
u_int8_t b = 1;
setxattr([path fileSystemRepresentation], “com.apple.MobileBackup”, &b, 1, 0, 0);
}
对文件夹的path使用这两个方法中的任意一个,就可以使该目录和该目录包含的所有文件和文件夹不被icloud和itunes同步了!
对于数据的同步与否的设计规则 详细看上面的官方说明链接。
注意:setxattr在iOS 5.0.1之前的系统里不会起作用的,(但是那些系统也没有iCloud只有iTunes^.^)。经测试发现虽然不会起作用,但调用该函数也不会引起空指针错误。 这是一项挺有意思的技术:新系统里加入了原先系统里没有的func,在原先的系统里调用,居然没有nullpoint错误。 莫非这函数地址早就存在,预留好了后面把功能挂上? 奇怪了。
另外补充一下,对这个特性的测试要有耐心,因为icloud识别应用程序里要同步的数据量大小显示要等几秒(菊花。。),
参考文档:apple官方文档,
stackoverflow问答:http://stackoverflow.com/questions/8694112/adding-the-do-not-backup-attribute-to-a-folder-hierarchy-in-ios-5-0-1
原文链接:http://chishangjin.sinaapp.com/?p=14
https://developer.apple.com/library/ios/#qa/qa1719/_index.html
使用方法:
#import “sys/xattr.h”
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
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;
}
- (void)addSkipBackupAttributeToPath:(NSString*)path {
u_int8_t b = 1;
setxattr([path fileSystemRepresentation], “com.apple.MobileBackup”, &b, 1, 0, 0);
}
对文件夹的path使用这两个方法中的任意一个,就可以使该目录和该目录包含的所有文件和文件夹不被icloud和itunes同步了!
对于数据的同步与否的设计规则 详细看上面的官方说明链接。
注意:setxattr在iOS 5.0.1之前的系统里不会起作用的,(但是那些系统也没有iCloud只有iTunes^.^)。经测试发现虽然不会起作用,但调用该函数也不会引起空指针错误。 这是一项挺有意思的技术:新系统里加入了原先系统里没有的func,在原先的系统里调用,居然没有nullpoint错误。 莫非这函数地址早就存在,预留好了后面把功能挂上? 奇怪了。
另外补充一下,对这个特性的测试要有耐心,因为icloud识别应用程序里要同步的数据量大小显示要等几秒(菊花。。),
参考文档:apple官方文档,
stackoverflow问答:http://stackoverflow.com/questions/8694112/adding-the-do-not-backup-attribute-to-a-folder-hierarchy-in-ios-5-0-1
原文链接:http://chishangjin.sinaapp.com/?p=14
相关文章推荐
- 如何阻止文件被iTunes和iCloud同步 How do I prevent files from being backed up to iCloud and iTunes?
- 如何从操作系统安装文件提取驱动文件/ How to extract driver files from setup files (win 7)
- How to Copy Archivelog Files From ASM to Filesystem and vice versa
- how to remove file and commit from history(如何移除 commit 歷史紀錄)
- How to create an XTR file from XML in Delphi XE4 using XML Mapper?(delphi中如何通过xmlmapper创建xtr文件)
- How to use logrotate to manage log files in linux(如何在Linux中使用logrotate去管理日志文件)
- 如何使用SSH向IPOD Touch2传输文件 - How to SSH into iPod Touch 2G [Transfer Files, Apps via SSH Access]
- 如何使用SSH向IPOD Touch2传输文件 - How to SSH into iPod Touch 2G [Transfer Files, Apps via SSH Access] 如何使用SSH向IPOD Touch2传输文件 - How to S
- 如何从EXCEL文件加载Hierarchy到BW (How to Load Hierarchy From Flat File)
- How to easily open files and URLs from the command line
- write to and read from files (读写文件)
- 如何象VS一样快速编辑Torque的CS文件(How to make your Torque CS files quickly)
- iphone游戏开发-Collisions and Collectables: How To Make a Tile Based Game with Cocos2D Part 2
- OS--阻止文件被iTunes和iCloud同步,Do Not Backup属性
- Linux恢复被删除的文件 How To Recover Deleted Files From Your Linux System
- How To Search and Restore files from Site Collection Recycle Bin
- How To Automate Cleanup Of Dead Connections And INACTIVE 【如何自动清理ORACLE中的死连接和非活动会话】
- 如何在MMIT上使用WMLScript文件(How To Use WMLScript Files With MMIT)
- How do I write to files using cheerio and request in node?
- How To Use XDOLoader to Manage, Download and Upload Files? (DOC ID 469585.1)