gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 20:09:05 25 4
gpt4 key购买 nike

我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com