admin管理员组文章数量:1416080
I use WKWebview.evaluateJavaScript() to execute javascript, I can get string, object and array from 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;
})
*/
While I execute this code
evaluateJavaScript("document.getElementById('test').getBoundingClientRect();")
//an object of { x: 0, y: 0, width: 0, height: 0, top: 0, right: 0, bottom: 0, left: 0 }
I get this error,
Optional(Error Domain=WKErrorDomain Code=5 "execute JavaScript unsupported return type" UserInfo={NSLocalizedDescription=execute JavaScript unsupported return type}) nil
Any help will appreciated, thank you.
I use WKWebview.evaluateJavaScript() to execute javascript, I can get string, object and array from 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;
})
*/
While I execute this code
evaluateJavaScript("document.getElementById('test').getBoundingClientRect();")
//an object of { x: 0, y: 0, width: 0, height: 0, top: 0, right: 0, bottom: 0, left: 0 }
I get this error,
Optional(Error Domain=WKErrorDomain Code=5 "execute JavaScript unsupported return type" UserInfo={NSLocalizedDescription=execute JavaScript unsupported return type}) nil
Any help will appreciated, thank you.
Share Improve this question asked Apr 26, 2017 at 2:51 LF-DevJourneyLF-DevJourney 28.6k30 gold badges165 silver badges316 bronze badges 2-
Shouldn’t
{a:1, b:2};
be({a:1, b:2});
? – Sebastian Simon Commented Apr 26, 2017 at 2:53 -
{a:1, b:2};
works well here. – LF-DevJourney Commented Apr 26, 2017 at 2:58
1 Answer
Reset to default 4I think here the result of document.getElementById('liveMovie').getBoundingClientRect();
is not support by swift.
So I change it to an array, like this,
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]
}
}
本文标签: iosUnsupported return type when execute javascriptStack Overflow
版权声明:本文标题:ios - Unsupported return type when execute javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745244450a2649491.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论