gpt4 book ai didi

ios - 数据txt文件在iPhone模拟器中读取时有效,但在iPhone设备上无效?

转载 作者:行者123 更新时间:2023-11-29 03:50:54 27 4
gpt4 key购买 nike

我的项目 bundle 的 Documents 目录中有两个文本文件 (.txt)。当我在 xCode 中的 iPhone 模拟器上运行该项目时,文件加载并工作正常,但是当我使用 iPhone 在 xCode 中运行相同的项目时,没有任何内容被加载。我检查过,当选择iPhone运行项目时,文件目录中甚至不存在这些文件。这是代码。同样,这工作正常,并且文件存在于 xCode 中的 iPhone 模拟器下运行,但当我使用 iPhone 作为设备运行它时,该文件不存在。

NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [arrayPaths objectAtIndex:0];

NSString *path = [docDir stringByAppendingPathComponent:CURRENTPUZZLENUMBERFILE];

NSLog(@"Path = %@", path); // for debugging
bool fileExists = [[NSFileManager defaultManager] fileExistsAtPath:path];
NSLog(@"File exists: %d", fileExists); // for debugging

最佳答案

通过这种方式获取文件,然后您可以根据需要将其复制到您的文档目录

NSString *filePath = [[NSBundle mainBundle] pathForResource:CURRENTPUZZLENUMBERFILE ofType:@"txt"];

关于ios - 数据txt文件在iPhone模拟器中读取时有效,但在iPhone设备上无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17074582/

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