I found this piece of code from anther post here. It worked as intended with iPad simulator mode but not when I switched to the actual iPad device mode. Instead, it came up with a “no such files exist” error message. Before executing this codes, I did create a the Populator folder by right-click on the xxxxxx.app and chose “show package contents” and put some files into the Populator folder. Does Xcode copy the whole app package over the iPad device? Any suggestions?
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Populator"];
NSString *folderPath = [documentsDirectory stringByAppendingPathComponent:@"Files"];
NSLog(@"Source Path: %@\n Documents Path: %@ \n Folder Path: %@", sourcePath, documentsDirectory, folderPath);
NSLog(@"docdire: %@", documentsDirectory);
NSLog(@"loadImage button clicked");
label.text = [@"sourcePath: " stringByAppendingString:sourcePath];
textField.text = [@"clicked: " stringByAppendingString:documentsDirectory];;
NSError *error;
if([[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:folderPath error:&error]){
NSLog(@"File successfully copied");
label.text = @"copy succeeded";
} else {
NSLog(@"Error description-%@ \n", [error localizedDescription]);
NSLog(@"Error reason-%@", [error localizedFailureReason]);
label.text = [@"Error description: " stringByAppendingString:[error localizedDescription]];
label2.text = [@"Error reason: " stringByAppendingString:[error localizedFailureReason]];
}
You cannot add files or folder to the NSBundle after it has been built. For the device, Xcode is going to sign the NSBundle. Whatever files and folders you want in the NSBundle on the device will have to be added to your Xcode project.
The other way to add files/folders to your NSBundle is during the build phase before the bundle is signed.