2

I recently got rejected for my NSLibraryDirectory backing up wrong kind of data to iCloud. I am trying to prevent the entire directory from backing up to iCloud, as this directory doesn't contain anything but downloaded content. Would this code in the AppDelegate.m work?

- (NSString *)applicationDocumentsDirectory {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

   NSURL *pathURL= [NSURL fileURLWithPath:documentsDirectory];
[self addSkipBackupAttributeToItemAtURL:pathURL];
return documentsDirectory;

}

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL

{ if (NSURLIsExcludedFromBackupKey) {
assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);



NSError *error = nil;

BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]

                              forKey: NSURLIsExcludedFromBackupKey error: &error];

if(!success){

    NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);

}

return success;
}
else {
assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);



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;
}

}
user717452
  • 33
  • 14
  • 73
  • 149
  • Ok, I changed a little bit up. In the applicationDidFinishLaunchingOptions part I added: `NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSURL *pathURL= [NSURL fileURLWithPath:documentsDirectory]; [self addSkipBackupAttributeToItemAtURL:pathURL];` and then left the BOOL Code alone – user717452 Jun 02 '12 at 23:53
  • You'll need to add the following to your header (.h) file to use the setxattr function: `#include ` – tombeynon Jan 08 '15 at 11:58

0 Answers0