I am storing some persistent data in /Documents directory which app gets from an API call and is needed to start the app. Apple rejected the app suggesting to skip the iCloud backup.
I used the code described in https://developer.apple.com/library/ios/#qa/qa1719/_index.html
which is
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;
}
It works fine with iOS 5.1 simulator. I checked in filesystem using
$xattr "filename"
and it shows me
filename: com.apple.metadata:com_apple_backup_excludeItem
However its not working on 5.0 simulator and also on 5.0.1 3GS device that I tested on.
I stepped thru the code and in the if part (<=5.0.1), I also printed the global var errno as suggested in the Technical Q&A article by apple. However the call to setxattr is failing and errno is printing to be 2 which is ENOENT as per http://developer.apple.com/library/ios/#documentation/system/conceptual/manpages_iphoneos/man2/intro.2.html
I am also printing out the filePath and its not empty and printing out correctly. I checked using iExplorer, the files are on the device as well as in the Simulator folder, they are getting created.
Has anyone faced this? Not sure how to address this?
Any help highly appreciated!
Thanks for you time.