无法将文件从主包复制到iPad上的文档目录

| 我从这里的其他花粉中找到了这段代码。它在iPad模拟器模式下可以正常工作,但是当我切换到实际的iPad设备模式时却无法正常工作。相反,它提出了“不存在这样的文件”错误消息。在执行此代码之前,我确实通过右键单击xxxxxx.app创建了Populator文件夹,然后选择\“ show package contents \”并将一些文件放入Populator文件夹。 Xcode是否可以在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]];
    }
    
已邀请:
        构建完NSBundle后,您无法将文件或文件夹添加到该NSBundle中。对于该设备,Xcode将对NSBundle进行签名。您想要在设备上的NSBundle中存储的任何文件和文件夹都必须添加到Xcode项目中。 将文件/文件夹添加到NSBundle的另一种方法是在对包进行签名之前的构建阶段。     
        如果没有访问实际文件列表的权限,则可能要检查文件名的大小写。 iPhone模拟器不区分大小写,而iPad文件系统区分大小写。过去,这使许多开发人员绊倒了。     
        就像我对原始问题的评论: 我发现有2个地方具有xxxxx.app软件包。一个用于模拟器,另一个用于构建分发。     

要回复问题请先登录注册