gpt4 book ai didi

ios - 在应用程序中找不到 'Folder referenced' 文件

转载 作者:行者123 更新时间:2023-11-29 11:59:00 24 4
gpt4 key购买 nike

我似乎无法在我的开发 iPhone 6 上引用与我的应用程序打包在一起的文件。可以在 XCode 的 iPhone 6 模拟器中找到它。

我要引用的文件:

enter image description here

我引用文件的地方:

NSString *epubPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"epubjs/ios.html"];

返回的错误:

Error Domain=NSCocoaErrorDomain Code=260 "The file “ios.html” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/containers/Bundle/Application/8BB11DEC-4823-4603-83E7-F4C23BC3C983/BSAVA.app/epubjs/ios.html, NSUnderlyingError=0x126df1110 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

我已经尝试了各种方法来获取 NSBundle 中的文件列表和/或搜索文件,但是当它在实际设备上运行时我无法在应用程序中找到它:

//
NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *dirContents = [fm contentsOfDirectoryAtPath:bundleRoot error:nil];
NSPredicate *fltr = [NSPredicate predicateWithFormat:@"self ENDSWITH '.html'"];
NSArray *onlyHTMLs = [dirContents filteredArrayUsingPredicate:fltr];
NSLog(@".html file array: %@", onlyHTMLs);
//
NSError * error;
NSString * resourcePath = [[NSBundle mainBundle] resourcePath];
NSArray * directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:resourcePath error:&error];
//
NSString * documentsPath = [resourcePath stringByAppendingPathComponent:@"BSAVA"];
NSArray * directoryContents2 = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsPath error:&error];
//
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"ios" ofType:@"html"];
NSURL *path = [[NSBundle mainBundle] URLForResource:@"ios" withExtension:@"html"];
//

这些都返回nil。

最佳答案

从评论中与您的对话来看,您似乎只是忘记了将文件与应用程序捆绑在一起,因此它们在运行时根本不存在。我不明白模拟器和设备之间的行为差​​异,但我希望这是一个转移注意力的问题,因为它应该在两者上都失败。

Apple Guide展示了如何在构建期间将文件复制到应用程序包中。

关于ios - 在应用程序中找不到 'Folder referenced' 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37830714/

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