从 NSBundle 中获取文件

Retrieving a file from NSBundle

我目前正在尝试将一个库集成到我的 ios 应用程序中。图书馆里有这样的东西

  // Serve files from the standard Sites folder
    NSString *docRoot = [[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"web"] stringByDeletingLastPathComponent];

现在我相信这会在目录 web 中找到 index.html。我确实有一个带有 index.html 的网络文件夹。但是我不确定 ios 应用程序在哪里寻找文件夹 web.有什么建议么 ?

NSBundle pathForResource:(NSString *)name ofType:(NSString *)extension inDirectory:(NSString *)bundlePathdocumentation,bundlePath参数对应:

The path of a top-level bundle directory. This must be a valid path. For example, to specify the bundle directory for a Mac app, you might specify the path /Applications/MyApp.app.

在这种情况下,您的网络文件夹应该位于您的 /MyApp/MyApp/ 目录中。

有一些示例说明 Bundle search pattern 如何工作和定位资源。

检查目录是否可读

参考:

+ (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension inDirectory:(NSString *)bundlePath

Return 值 资源文件的完整路径名,如果找不到文件则为 nil。如果 bundlePath 参数指定的包不存在或不是可读目录,此方法也 returns nil。