mobile - Phonegap 是如何工作的?

标签 mobile cordova hybrid

我们使用 PhoneGap 来使用移动设备的 native 功能。内部如何运作?我们如何能够从 JavaScript 方法访问 PhoneGap 的实现类?有人可以解释一下吗?

最佳答案

我对 Cordova iOS 如何将消息传递给 WebView 做了一些深入研究。这是将消息从 iOS 传递到 JavaScript 的方法。
UIWebView 类有一个名为 stringByEvaluatingJavaScriptFromString 的方法.
如果您查看 iOS Cordova 项目中的一些文件,它们会将 JavaScript 作为要执行到该函数的字符串传递,例如CDVPlugin.m .
我不知道 iOS 是编写一个新的 DOM 节点(类似于 <script>alert('from iOS');</script> )还是通过 Safari 中的一个特殊钩子(Hook)执行 JavaScript。我相信后者,在这方面,上面引用的文档说:

JavaScript execution time is limited to 10 seconds for each top-level entry point. If your script executes for more than 10 seconds, the web view stops executing the script. This is likely to occur at a random place in your code, so unintended consequences may result. This limit is imposed because JavaScript execution may cause the main thread to block, so when scripts are running, the user is not able to interact with the webpage.

JavaScript allocations are also limited to 10 MB. The web view raises an exception if you exceed this limit on the total memory allocation for JavaScript.


我不知道如果不对 UIWebView 的内部状态进行一些特殊访问,他们实际上是如何施加这些限制的,所以我怀疑他们只是在插入一个新的 DOM 节点。

关于mobile - Phonegap 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10804772/

相关文章:

ios - meteor + Cordova + iOS : unallowed to upload file

iphone - iPhone上的来电后,Phonegap HTML5音频无法继续播放

html - 在 Windows Phone 8 的 cordova 应用程序中禁用用户缩放

macos - 如何发布一个用flutter编写的macos应用

azure - 无法在 Azure 门户中创建混合连接

javascript - 移动 JavaScript 事件多次触发

mobile - 谁能猜出这些数据包属于什么协议(protocol)?

templates - 如何在 SMARTY 中重定向到移动模板

Flutter VLC 播放器及选项

android - Cordova 抛出异常跨源请求仅支持协议(protocol)方案