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

标签 ios objective-c cocoa-touch

我似乎无法在我的开发 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/

相关文章:

ios - 无效的 ipa 文件 : info. plist is missing CFBundleName error showing when upload ipa file on diawi

ios - IOS UIScrollView 中位置坐标值加倍

ios - 为什么在 Swift 中转换成本如此之高,而不是……将其保留为 AnyObject?

cocoa-touch - 通过FMDatabase读写NSDate到sqlite数据库

ios - 有没有办法在iOS上接收亚精度触摸事件?

iphone - 将 webview 中的照片保存到 ios 照片库

iphone - 在 Objective-C 中,我们如何称呼 "[ob method]"语法?

ios - 解雇 Controller 后未调用委托(delegate)

ios - 从 dispatch_async 修改时 UIView 不变

ios - 如何将 'Any?' 转换为具有灵活通用属性的结构?