Ios5 在iOS 5.0或更低版本上,setxattr失败,错误为2(eNot)

Ios5 在iOS 5.0或更低版本上,setxattr失败,错误为2(eNot),ios5,backup,icloud,Ios5,Backup,Icloud,我正在/Documents目录中存储一些持久性数据,该目录是应用程序从API调用中获取的,并且是启动应用程序所需的。苹果拒绝了建议跳过iCloud备份的应用程序 我使用了中描述的代码 那是 if (&NSURLIsExcludedFromBackupKey == nil) { // iOS <= 5.0.1 assert([[NSFileManager defaultManager] fileExistsAtPath: path]); const

我正在/Documents目录中存储一些持久性数据,该目录是应用程序从API调用中获取的,并且是启动应用程序所需的。苹果拒绝了建议跳过iCloud备份的应用程序

我使用了中描述的代码

那是

if (&NSURLIsExcludedFromBackupKey == nil) { // iOS <= 5.0.1
        assert([[NSFileManager defaultManager] fileExistsAtPath: path]);

        const char* filePath = [path fileSystemRepresentation];
        printf("[path fileSystemRepresentation] %s\n",filePath);
        const char* attrName = "com.apple.MobileBackup";
        u_int8_t attrValue = 1;
        int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
        NSLog(@"errno %d", errno);
        return result == 0;
    } else { // iOS >= 5.1
        NSURL* url = [NSURL fileURLWithPath:path];
        NSError *error = nil;
        BOOL success = [url setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
        NSLog(@"Error excluding %@ from backup %@", [url lastPathComponent], error);
        return success;

    }
它告诉我

filename: com.apple.metadata:com_apple_backup_excludeItem
然而,它不能在5.0模拟器上工作,也不能在我测试的5.0.1 3GS设备上工作


我一步一步地浏览了代码,在if部分(Ok…我的错…它做的一切都是正确的。如果成功执行setxattr,它应该返回0…但是它仍然返回一个错误代码,这让我感到困惑…不管怎样,代码按预期工作

filename: com.apple.metadata:com_apple_backup_excludeItem