从NSBundle检索文件

时间:2015-04-21 01:36:38

标签: ios nsbundle

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

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

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

2 个答案:

答案 0 :(得分:0)

NSBundle pathForResource:(NSString *)name ofType:(NSString *)extension inDirectory:(NSString *)bundlePath documentation开始,bundlePath参数对应于:

  

顶级捆绑目录的路径。这必须是有效的路径。例如,要指定Mac应用程序的软件包目录,可以指定路径/​​Applications/MyApp.app。

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

有一些关于Bundle search pattern如何工作和定位资源的例子。

答案 1 :(得分:0)

检查目录是否可读

<强>参考:

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

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