WKWebView無法在iOS 8下加載本地文件對于以前的iOS測試版8,負荷(束)本地web應用程序,它都為正常工作UIWebView和WKWebView,我甚至移植使用新的網頁游戲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仍在工作),看起來沒有任何內容被加載或執(zhí)行。我在日志中看到一個錯誤:無法為其創(chuàng)建沙箱擴展 /有沒有幫助引導我走向正確的方向?謝謝!
3 回答

繁星淼淼
TA貢獻1775條經驗 獲得超11個贊
在iOS 9上如何使用[WKWebView loadFileURL:allowsReadAccessToURL:]的示例。
將Web文件夾移動到項目時,選擇“創(chuàng)建文件夾引用”
然后使用類似這樣的代碼(Swift 2):
if let filePath = NSBundle.mainBundle().resourcePath?.stringByAppendingString("/WebApp/index.html"){ let url = NSURL(fileURLWithPath: filePath) if let webAppPath = NSBundle.mainBundle().resourcePath?.stringByAppendingString("/WebApp") { let webAppUrl = NSURL(fileURLWithPath: webAppPath, isDirectory: true) webView.loadFileURL(url, allowingReadAccessToURL: webAppUrl) }}
在html文件中使用像這樣的文件路徑
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
不喜歡這個
<link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet">
移動到xcode項目的目錄示例。
- 3 回答
- 0 關注
- 1301 瀏覽
添加回答
舉報
0/150
提交
取消