WKWebView无法在iOS 8下加载本地文件

WKWebView无法在iOS 8下加载本地文件

对于以前的iOS测试版8,负荷(束)本地web应用程序,它都为正常工作UIWebViewWKWebView,我甚至移植使用新的网页游戏WKWebViewAPI。

var url = NSURL(fileURLWithPath:NSBundle.mainBundle().pathForResource("car", ofType:"html"))webView = WKWebView(frame:view.frame)webView!.loadRequest(NSURLRequest(URL:url))view.addSubview(webView)

但在测试版4中,我只是得到了一个空白的白色屏幕(UIWebView仍在工作),看起来没有任何内容被加载或执行。我在日志中看到一个错误:

无法为其创建沙箱扩展 /

有没有帮助引导我走向正确的方向?谢谢!


FFIVE
浏览 1225回答 3
3回答

繁星淼淼

在iOS 9上如何使用[WKWebView loadFileURL:allowsReadAccessToURL:]的示例。将Web文件夹移动到项目时,选择“创建文件夹引用”然后使用类似这样的代码(Swift 2):if&nbsp;let&nbsp;filePath&nbsp;=&nbsp;NSBundle.mainBundle().resourcePath?.stringByAppendingString("/WebApp/index.html"){ &nbsp;&nbsp;let&nbsp;url&nbsp;=&nbsp;NSURL(fileURLWithPath:&nbsp;filePath) &nbsp;&nbsp;if&nbsp;let&nbsp;webAppPath&nbsp;=&nbsp;NSBundle.mainBundle().resourcePath?.stringByAppendingString("/WebApp")&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;let&nbsp;webAppUrl&nbsp;=&nbsp;NSURL(fileURLWithPath:&nbsp;webAppPath,&nbsp;isDirectory:&nbsp;true) &nbsp;&nbsp;&nbsp;&nbsp;webView.loadFileURL(url,&nbsp;allowingReadAccessToURL:&nbsp;webAppUrl) &nbsp;&nbsp;}}在html文件中使用像这样的文件路径<link&nbsp;href="bootstrap/css/bootstrap.min.css"&nbsp;rel="stylesheet">不喜欢这个<link&nbsp;href="/bootstrap/css/bootstrap.min.css"&nbsp;rel="stylesheet">移动到xcode项目的目录示例。
打开App,查看更多内容
随时随地看视频慕课网APP