ios - 我可以用 "do not backup"属性标记文档目录吗?

标签 ios backup

我读过我可以用“不备份”属性标记文件夹。
据我了解,在这种情况下,目录的所有内容都将从备份中排除。
在我们的应用程序中,我们需要从备份中排除文档目录中的所有文件(可以在应用程序执行期间从文档中添加或删除这些文件)。
我们需要将文件存储在 Documents 中,因为我们使用“应用程序支持 iTunes 文件共享”功能。
能否给Documents目录加上“不备份属性”?
Apple 允许这样做吗?
这会成为拒绝我们应用程序的理由吗?

最佳答案

据苹果称

In iOS 5.0 and earlier, put files in the /Library/Caches directory to prevent them from being backed up

In iOS 5.0.1 and later, put files in the /Library/Application Support directory and apply the com.apple.MobileBackup extended attribute to them. This attribute prevents the files from being backed up to iTunes or iCloud. If you have a large number of support files, you may store them in a custom subdirectory and apply the extended attribute to just the directory.

据我所知 您不能使用不备份属性标记文档目录

1)您可以使用以下代码片段标记文档目录中的各个文件

- (BOOL)addSkipBackupAttributeToItemAtPath:(NSString *)filePathString {
        NSURL *fileURL =
        [NSURL fileURLWithPath:filePathString];

        assert([[NSFileManager defaultManager] 
        fileExistsAtPath: [fileURL path]]);

        NSError *error = nil;

        BOOL success = [fileURL setResourceValue:[NSNumber numberWithBool:YES]
                                      forKey:NSURLIsExcludedFromBackupKey
                                     error:&error];
        return success;
    }

2)您可以在文档文件夹中创建一个子目录,并对其应用扩展属性。

您可以使用以下语法设置扩展属性。

int result = setxattr(path, attrName, myDataBytes, [myData length], 0, 0);

您可以在以下link 中找到有关读写扩展属性的更多信息

希望对你有帮助

关于ios - 我可以用 "do not backup"属性标记文档目录吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16009693/

相关文章:

bash - 如何使用 Cron 备份我的 PostgreSQL 数据库?

ios - iPhone SDK : UIWebView crash

ios - UITableViewController 上的自定义弹出窗口可滑动 - 如何防止 - Swift

ios - 根据变量使用不同的图像初始化 UIImageView

ios - 如何在同一个iOS项目中使用多个Icomoon字体?

backup - rsync "failed to set times on "XYZ“: No such files or directory (2)

android - iOS 推送通知 iBeacon Estimote

azure - 使用自定义年度策略 json 创建 az 备份策略

java - java备用备份轮换算法

java - 检查两个(大)文件之间的差异