My app was rejected because I use Documents directory to store a few files that I download from my server.
I've readed this from Apple's docs: https://developer.apple.com/library/ios/#qa/qa1719/_index.html and I've found this code: addSkipBackupAttributeToItemAtURL -> NSString parameter?
I was reading also that this code will be usefull for iOS versions >= 5.0.1. And that iOS versions < 5 don't use iCloud to backup user data. But that iOS == 5.0 uses iCloud to backup data but the flag dosn't work.
So, I have two questions:
First I need files in my application to work (like the database). And if I store those files in Caches directory whenever that iOS wants can delete my files. So I am storing my files in Documents directory ie:
/Documents/db.db
/Documents/my.plist
After that I store my files in that directory I call to the method addSkipBackupAttributeToItemAtURL for every file that I put in that directory. But I don't know how can I test if this is method is working.
I've readed here iOS 5.0.1 : How to verify that the folder is marked as "Do not back up" for iCloud? that if I use the simulator I can go to the Application's directory and run this command
xattr -plxv com.apple.MobileBackup <file name>
to know if the file has been marked to not be backed up.
But if I run that command in the command line I get for every file this result:
xattr: my.plist: No such xattr: com.apple.MobileBackup
So, the first question is: how can I be sure that my files under Documents directory are being correctly marked to not be backed up. I don't want to upload again my app to the AppStore and that Apple's people throw it down again.
Second, my application runs with iOS 5. And I don't want to check for every file if the user has iOS 5.0 and store it in Caches directory and every time that I need to use the file check if the "stills" there. I have a 500mb database that I can't be downloading everytime.
So, second question is: if in "iOS Deployment Target" I choose 5.1 and in Build Settings > Base SDK I also choose 5.1 it means that users with iOS version < 5.1 wouldn't can download my app, right? So I don't need to be affraid of take of my data with users with iOS 5.0, right?
If your target is >= iOS 5.1 below code will help you. Use the below method for excluding the item from being backed up on iCloud. You can even use this code for excluding an entire folder
- (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;
}