我在这里找到了这篇帖子。它在iPad模拟器模式下按照预期工作,但在切换到实际的iPad设备模式时无法使用。相反,它提出了“没有这样的文件存在”的错误信息。在执行这些代码之前,我确实通过右键单击xxxxxx.app创建了一个Populator文件夹,然后选择“显示包内容”并将一些文件放入Populator文件夹。 Xcode是否将整个应用程序包复制到iPad设备上?有什么建议么?无法将文件从主包复制到iPad上的文档目录
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]];
}
我发现有2个地方有xxxxx.app包。一个用于模拟器,另一个用于构建分布。 – user523234 2011-06-01 00:42:03