1

我发现了几个类似的问题: link1 link2

我添加了链接2中描述的代码:我在图片下载并保存在目录后调用此方法。

-(BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL {
assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);

if (&NSURLIsExcludedFromBackupKey == NULL) {
    // Use iOS 5.0.1 mechanism

    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;
}
else {
    // Use NSURLIsExcludedFromBackupKey mechanism, iOS 5.1+
    NSError *error = nil;
    BOOL success = [URL setResourceValue:[NSNumber numberWithBool:YES]
                                  forKey:NSURLIsExcludedFromBackupKey
                                   error:&error];
    if(!success) {
        NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
    }
    else {
        NSLog(@"Path is %@:", [URL path]);
    }
    //Check your error and take appropriate action
    return success;
}

}

在 iCloud 中签入时,应用程序的大小仍然是 50.7 Mb(我正在使用 5.1.1 iOS 版本的 iPhone 上进行测试),因此使用 of flag 没有任何效果,尽管成功有一个“YES”值。请告诉我我做错了什么?

4

1 回答 1

0

问题在于制作文件路径 URL 的方法。目前我已更改为 + fileURLWithPath:isDirectory: 并且一切正常。我的应用程序在 iCloud 存储中的大小显示为 0.9KB(以前是 50.7Mb)。

于 2013-06-22T08:39:41.147 回答