Android Webview 的 callAsyncJavascript (IOS) 的等效项
我正在研究一个使用有关iOS和Android的网络浏览量的项目。 I have some native methods which call some javascript methods with the evaluateJavascript
webview method which is available from the
由于我需要得到JS承诺的结果,因此我使用在iOS方面。
问题是我在Android方面找不到任何callasyncjavascript
,但我看到它存在于 flutter 。
有人对此有一些了解吗?在Android上是否有等效的?还是颤动如何在内部进行管理?
这是我在iOS上使用的一些代码:
let script = """
return window.myJsMethod().then(({id}) => id);
"""
webView.callAsyncJavaScript(script, in: nil, in: .page, completionHandler: { result in
switch result {
case let .failure(error):
debugPrint("failure \(error)")
case let .success(result):
completion?(result as! String)
}
})
I'm working on a project which uses a webview on IOS and Android. I have some native methods which call some javascript methods with the evaluateJavascript
webview method which is available from the IOS and Android.
Since I need to get the result of a JS promise, I'm using callAsyncJavascript on the IOS side.
The issue is I can't find any callAsyncJavascript
on the Android side but I saw that it exists on Flutter.
Did someone have some knowledge about this? Is there some equivalent on Android? Or how does Flutter manage this internally?
Here is some code I'm using on IOS:
let script = """
return window.myJsMethod().then(({id}) => id);
"""
webView.callAsyncJavaScript(script, in: nil, in: .page, completionHandler: { result in
switch result {
case let .failure(error):
debugPrint("failure \(error)")
case let .success(result):
completion?(result as! String)
}
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果有些人有兴趣,我找到了一种在Android上实现
callasyncjavascript
,通过遵循Flutter软件包的实现 flutter_inappwebviewYou can find its code
If there is some people interested, I found a way to implement
callAsyncJavascript
on Android by following the implementation of the flutter package flutter_inappwebviewYou can find its code here