【发布时间】:2018-07-25 01:42:07
【问题描述】:
大家!
我有 WKWebView,它在里面加载带有 js 的本地 XML。
function loadSegment(url,uuid) {
let xhr = new XMLHttpRequest();
xhr.onerror = () => rejected();
xhr.onabort = () => rejected();
xhr.ontimeout = () => rejected();
xhr.onload = () => xhr.status === 200 ? handleSegment(url, uuid, xhr.response) : rejected();
xhr.open("GET", url);
xhr.responseType = "arraybuffer";
xhr.send(null)
}
function handleSegment(url,uuid,res) {
// url, uuid, res to json
// webkit.messageHandlers.LoadHandler.postMessage(<#JSON#>)
}
function rejected() {
}
WebView 成功加载文件后我评估
webView.evaluateJavaScript(script, completionHandler: { (response, error) in
// Error handling
}
脚本评估成功。但在 Safari Inspector 中,我看到以下错误
[Error] Failed to load resource: The network connection was lost. (05.ts, line 0)
[Error] Failed to load resource: A server with the specified hostname could not be found. (05.ts, line 0)
它尝试执行以下 url 的请求:http://edge.flowplayer.org/cilla_black_bean_sauce/1/216p-lo/00.ts
最奇怪的是它在模拟器上完美运行。
有没有人遇到过类似的问题?
【问题讨论】:
-
可能是 CORS。这是从“edge.flowplayer.org”调用的???,如果不是,那就是CORS。 (跨域请求)
-
感谢您的回答。不是来自“edge.flowplayer.org/”。如果是 CORS,真实设备有什么问题?
-
阅读这个,developer.mozilla.org/en-US/docs/Web/HTTP/CORS你可以找到解决办法
标签: javascript ios swift xmlhttprequest wkwebview