不知道看了多少论坛,实在不知道为什么不行!
我有一个 iPhone 应用程序,我想向我的用户展示一本 Epub 图书。
用户可以在线阅读,也可以下载到Application Documents目录下以后阅读。
我构建了与在线版本相同的文件夹结构,并将其保存到文档文件夹“frontend”中。
我也可以阅读这个维护的 .HTML 文件,但是链接的 JS/CSS 和 HTML 文件不起作用。
所以我有一些截图。我不知道,为什么 javascript 无法访问 .html 文档。
offline version - saved into the filesystem "document folder"
online version - directly from server - it's ok!
我希望你能给我一些提示。
最佳答案
简单写代码
NSString *path = [[NSBundle mainBundle] pathForResource:@"offlineEpub" ofType:@"html"];
NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
UIWebView *webView = [[UIWebView alloc] init];
[webView loadHTMLString:content baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
[self.view addSubview:webView];
主要是提供基本 url 作为您的 mainBundle 或文档目录。
关于javascript - UIWebView - 加载带有链接资源的本地 .html 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13289589/