Comments (3)
你native实现方式有问题,无论何时testAsyn都会被同步调用,只是completionHandler调用时才会触发js回调, sleep直接阻塞线程,所谓支持异步,是客户端的任务实现本身就要是异步的。
from dsbridge-ios.
相当于JS端必须同步的调Native端的方法,如果Native对应的方法耗时太多也会阻塞JS端的线程,所谓的“异步”只能在Native端方法写“异步”处理?
No I don't believe it is possible due to the multi-process architecture of WKWebView. WKWebView runs in the same process as your application but it communicates with WebKit which runs in its own process (Introducing the Modern WebKit API). The JavaScript code will be running in the WebKit process. So essentially you are asking to have synchronous communication between two different processes which goes against their design
用原生的方式JS-Native异步调用和这个框架“异步”是有区别的
[controller addScriptMessageHandler:self name:@"observe"];
- (void)userContentController:(WKUserContentController *)userContentController
didReceiveScriptMessage:(WKScriptMessage *)message
可以参加下这个Demo,加Native端加了sleep函数 JS端也不会block
from dsbridge-ios.
Native对应的方法耗时太多的话,我觉得应该由程序员在Native进行显式的异步处理。你的这种场景,其实就是:只要js以异步方式调用,即使native端是同步处理的,对于js来说也要是异步的。这样的话如果所有异步任务,natvie端都以同步的方式来处理,同时使用messageHandler 来做,是有问题的,原因如下:WKWebView处理js消息是在一个单独的线程,如果端上还是同步的写法,那么任务多时,必定是要排队的,native端的任务就会阻塞,这会导致native端执行完所有的“异步任务”的总时长延长,因为只有一个线程。这样虽然js不会阻塞,但是native端还是会阻塞,而解决的方法还是要在MessageHandler中手动开线程。所以我认为,任务是否是异步应该接口提供方自己决定,而不是调用方。不过WKWebview中用MessageHandler的方式是好一些,职责分离,但由于目前DSBridge目前支持UIWebview,也是为了统一的行为,之后的版本可能会使用MessageHandler。
from dsbridge-ios.
Related Issues (20)
- 原生异步函数如何支持重载?
- 获取网络数据后给前端传值不显示
- 崩溃ret=action(JavascriptInterfaceObject,sel,arg); HOT 2
- 使用dsBridge.call("name", "msg") msg 内容超过一定长度会被截断问题
- 使用 UIWindowSceneDelegate 的情况下,会导致奔溃(crash)
- addJavascriptObject方法添加的函数异步执行问题。 HOT 1
- 我已经重新设计了新的交互库,10分钟就能完成接入,也许可以帮助你. HOT 1
- I have redesigned new libraries, It only takes ten minutes to complete . Maybe can help you.
- 通过dsbridge.call调用,iOS端接收到的信息不正确
- 请问 dsuiDelegate 与 requestMediaCapturePermissionFor 代理实现 HOT 2
- oc 调用 js 只能传数组么?
- [ios]When webview video on full screen, js call native dsbridge will exit the fullscreen
- 新版xcode namespace命名与系统关键字冲突了
- 求助 swift js 调原生,异步有传参和回调,点击报错[__NSCFString count] HOT 1
- completionHandler
- 高频调用时会丢包 HOT 1
- 加载网页资源loadrequest,添加javascript无法响应 HOT 5
- 你好,希望添加对 Swift packages 的支持
- Xcode 15 打包,dsbridge失效 HOT 1
- 老铁们,DSBridge-HarmonyOS 版本来了
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dsbridge-ios.