【发布时间】:2011-09-05 21:42:44
【问题描述】:
我从这里的另一个帖子中找到了这段代码。它在 iPad 模拟器模式下按预期工作,但在我切换到实际 iPad 设备模式时却没有。相反,它提出了“不存在此类文件”错误消息。在执行此代码之前,我确实通过右键单击 xxxxxx.app 并选择“显示包内容”创建了一个 Populator 文件夹,并将一些文件放入 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]];
}
【问题讨论】:
-
我发现有 2 个地方有 xxxxx.app 包。一个用于模拟器,另一个用于构建分发。
标签: iphone objective-c cocoa-touch ipad nsfilemanager