i am storing some downloaded files in NSDocumentDirectory and i need to mark those files as “do not backup”.
here is the code i have given
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL1
{
if (&NSURLIsExcludedFromBackupKey == nil) { // iOS <= 5.0.1
const char* filePath = [[URL1 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 { // iOS >= 5.1
NSError *error = nil;
[URL1 setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
return error == nil;
NSLog(@"success");
}
}
littile bit confused about which url should given for ths method? downloading url or the downloaded file path url?
can i use like
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [[paths objectAtIndex:0]stringByAppendingPathComponent:@"MdMus.mp3"];
[receivedData writeToFile:documentsDirectoryPath atomically:YES];
need to use this one
NSURL *url=[NSURL fileURLWithPath:documentsDirectoryPath];
[self addSkipBackupAttributeToItemAtURL:url];
or this
[self addSkipBackupAttributeToItemAtURL:DownloadingURL];
need help
if you want filesharing all user-data(in DocumentDirectory all data) prevent backup. refer a following code.