Hi,
during the startup of my app, I'm trying to copy some sample resources from the application bundle to the "Documents/Inbox" directory but for some reason it fails on a real device and works on the simulator.
The "copyItemAtPath:sourcePath" fails with a "The operation couldnt be completed. Operation not permitted" error. What am I doing wrong ?
thanks for the help
during the startup of my app, I'm trying to copy some sample resources from the application bundle to the "Documents/Inbox" directory but for some reason it fails on a real device and works on the simulator.
Code:
-(void) copyTestDocuments {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = paths[0];
// CREATE THE "Inbox" folder
NSFileManager *fileManager = [NSFileManager defaultManager];
documentsPath = [documentsPath stringByAppendingString:@"/Inbox/"];
if ([fileManager fileExistsAtPath:documentsPath] == NO) {
NSLog(@"Creating directory %@",documentsPath);
NSError *error;
BOOL success = [fileManager createDirectoryAtPath:documentsPath withIntermediateDirectories:YES attributes:nil error:&error];
if (!success) {
NSLog(@"failed: %@", error);
}
}
// copy the two PDFs
NSArray * pdfArray = @[@"201.pdf", @"iOS_Security_May12.pdf"];
for(NSString *pdfName in pdfArray) {
NSString *txtPath = [documentsPath stringByAppendingPathComponent:pdfName];
if ([fileManager fileExistsAtPath:txtPath] == NO) {
NSLog(@"Copying test document %@", pdfName);
NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:pdfName];
NSError *error;
// this fails
BOOL success = [fileManager copyItemAtPath:sourcePath toPath:txtPath error:&error];
if (!success) {
NSLog(@"failed: %@", [error localizedDescription]);
}
}
}
}
The "copyItemAtPath:sourcePath" fails with a "The operation couldnt be completed. Operation not permitted" error. What am I doing wrong ?
thanks for the help
Last edited: