2015-04-21 52 views
0

我正在尝试将库集成到我的ios应用程序中。该库中有从NSBundle检索文件

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

这样的事情现在我相信这个座落在目录网页的index.html。我确实有一个带有index.html的web文件夹。不过,我不确定ios应用程序在哪里查找文件夹网页。有什么建议么 ?

回答

0

检查该目录是可读

参考:

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

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

0

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

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

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

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

+0

我把web文件夹放在'.xcodeproj'文件的旁边。然而它仍然没有被拾起 – Rajeshwar

+0

您是否使用将文件添加到将文件夹添加到项目中? – romsearcher

+0

通过使用上述方法添加文件夹,文件夹将位于您的文件夹内,而不是位于.xcodeproj旁边。 – romsearcher