执行 javascript 时不支持 return 类型
Unsupported return type when execute javascript
我使用WKWebview.evaluateJavaScript()来执行javascript,我可以从javascript.
得到字符串、对象和数组
evaluateJavaScript("document.getElementById('title').innerHTML;")
/*
output:
Optional(hhhhhhhhhhhhhh)
*/
evaluateJavaScript("[1,2];")
/*
output:
Optional(<__NSArrayM 0x17005faa0>(
1,
2
)
*/
evaluateJavaScript("{a:1, b:2};")
/*
output:
Optional({
a = 1;
b = 2;
})
*/
当我执行这段代码时
evaluateJavaScript("document.getElementById('test').getBoundingClientRect();")
//an object of { x: 0, y: 0, width: 0, height: 0, top: 0, right: 0, bottom: 0, left: 0 }
我收到这个错误,
Optional(Error Domain=WKErrorDomain Code=5 "execute JavaScript unsupported return type"
UserInfo={NSLocalizedDescription=execute JavaScript unsupported return type}) nil
任何帮助将不胜感激,谢谢。
我认为 document.getElementById('liveMovie').getBoundingClientRect();
的结果不被 swift 支持。
所以我把它改成一个数组,像这样,
self.wk.evaluateJavaScript("var rect = document.getElementById('liveMovie').getBoundingClientRect();[rect.left, rect.top];") {
(result, error) -> Void in
if((result) != nil)
{
self.player?.view?.frame.origin.x = (result as! Array)[0]
self.player?.view?.frame.origin.y = (result as! Array)[1]
}
}
我使用WKWebview.evaluateJavaScript()来执行javascript,我可以从javascript.
得到字符串、对象和数组evaluateJavaScript("document.getElementById('title').innerHTML;")
/*
output:
Optional(hhhhhhhhhhhhhh)
*/
evaluateJavaScript("[1,2];")
/*
output:
Optional(<__NSArrayM 0x17005faa0>(
1,
2
)
*/
evaluateJavaScript("{a:1, b:2};")
/*
output:
Optional({
a = 1;
b = 2;
})
*/
当我执行这段代码时
evaluateJavaScript("document.getElementById('test').getBoundingClientRect();")
//an object of { x: 0, y: 0, width: 0, height: 0, top: 0, right: 0, bottom: 0, left: 0 }
我收到这个错误,
Optional(Error Domain=WKErrorDomain Code=5 "execute JavaScript unsupported return type" UserInfo={NSLocalizedDescription=execute JavaScript unsupported return type}) nil
任何帮助将不胜感激,谢谢。
我认为 document.getElementById('liveMovie').getBoundingClientRect();
的结果不被 swift 支持。
所以我把它改成一个数组,像这样,
self.wk.evaluateJavaScript("var rect = document.getElementById('liveMovie').getBoundingClientRect();[rect.left, rect.top];") {
(result, error) -> Void in
if((result) != nil)
{
self.player?.view?.frame.origin.x = (result as! Array)[0]
self.player?.view?.frame.origin.y = (result as! Array)[1]
}
}