xcode - 将数据文件从 Xcode 复制到 iPad 沙箱

标签 xcode ios5 testing ios-simulator

我在 Xcode 中创建了一个应用程序,并添加了一个文本文件供该应用程序打开和显示。

如何将此文本文件放入 iPad 沙箱文档目录进行测试?

最佳答案

有几件事你需要做:

  1. 创建您的文档目录的路径
  2. 确保您的文本文件在您的应用程序包中(拖放到 Xcode 中应该没问题)
  3. 按名称将该文本文件从应用程序包复制到 Documents 目录

试试这个:

// Documents path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];

// Destination path
NSString *fileInDocumentsPath = [documentsPath stringByAppendingPathComponent:@"name-of-your-file.txt"];

// Origin path
NSString *fileInBundlePath = [[NSBundle mainBundle] pathForResource:@"name-of-your-file" ofType:@"txt"];

// File manager for copying
NSError *error = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager copyItemAtPath:fileInBundlePath toPath:fileInDocumentsPath error:&error];

关于xcode - 将数据文件从 Xcode 复制到 iPad 沙箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15843870/

相关文章:

eclipse - 如何在 Eclipse 中轻松创建单元测试

c++ - 有没有人成功为 ARC 移植 SpeakHere?

android - 获取资源编号 0xffffffff 的名称时没有已知包

android - Xcode 打不开 "Required content for Platform Android is missing"

ios - Xcode IOS 如何访问未知文件名的文件

iphone - iOS5 数据存储问题。在哪里保存文件?

ios - 如果已经自定义,如何覆盖 UINavigationBar 外观

testing - 什么被认为是 "best practice"来测试 akka 中的语义竞争条件?

ios - 如何检查文件是否存在于 Swift 的 Documents 目录中?

javascript - 如何获取ios中UIWebview中的内容