Android Webview 的 callAsyncJavascript (IOS) 的等效项

发布于 2025-01-20 21:41:14 字数 1077 浏览 2 评论 0原文

我正在研究一个使用有关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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

左岸枫 2025-01-27 21:41:14

如果有些人有兴趣,我找到了一种在Android上实现callasyncjavascript,通过遵循Flutter软件包的实现 flutter_inappwebview

You 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_inappwebview

You can find its code here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文