2011-06-01 123 views
0

我在这里找到了这篇帖子。它在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]]; 
    } 
+0

我发现有2个地方有xxxxx.app包。一个用于模拟器,另一个用于构建分布。 – user523234 2011-06-01 00:42:03

回答

3

构建完成后,无法将文件或文件夹添加到NSBundle。对于该设备,Xcode将签署NSBundle。无论您在设备上的NSBundle中需要什么文件和文件夹,都必须添加到您的Xcode项目中。

将文件/文件夹添加到NSBundle的另一种方式是在捆绑包签署之前的构建阶段。

0

无法访问实际文件列表,您可能想检查文件名的大小写。 iPhone模拟器不区分大小写,而iPad文件系统则区分大小写。这在过去让许多开发者绊倒了。

0

正如我在原来的问题评论:

我发现有2处具有xxxxx.app包。一个用于模拟器,另一个用于构建分布。

相关问题