gpt4 book ai didi

javascript - evaluateJavascript 只在主线程中运行?

转载 作者:行者123 更新时间:2023-11-29 17:48:25 24 4
gpt4 key购买 nike

我尝试在我的主线程中使用 evaluateJavascript 方法,它工作正常。但是如果我将函数移动到我的另一个线程(我有一个服务在后台运行等待消息)。它根本不起作用。所以我假设 evaluateJavascript 只适用于主线程,也就是 UI 线程。这是事实还是我做错了什么?

`myWebView.evaluateJavascript("test()", null);`

test()是HTML应用中的方法

有没有办法在其他线程调用evaluateJavascript?

最佳答案

根据文档:

Asynchronously evaluates JavaScript in the context of the currently displayed page. If non-null, |resultCallback| will be invoked with any result returned from that execution. This method must be called on the UI thread and the callback will be made on the UI thread.

所以它默认是异步运行的,必须在UI线程中使用,即不需要自己创建一个单独的线程。

关于javascript - evaluateJavascript 只在主线程中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24768059/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com