We use PhoneGap to use native capability of a mobile device. How does is work internally? How are we able to access PhoneGap's implementation classes from a JavaScript method? Can someone please explain this?
PhoneGap is an Open Source framework that helps build hybrid applications which work on most mobile platforms such as Android, iOS, Blackberry, Windows Phone among others. Framework provides a container that bridges the native APIs to the web view.
PhoneGap is a mobile development framework built on top of the Apache Cordova platform, allowing developers who don't have experience in JAVA or Objective-C to create applications on the most popular mobile platforms (Android, iOS, Windows Phone) by using JavaScript, HTML5 and CSS.
What is Phonegap ? PhoneGap is an open source framework for quickly building cross-platform mobile apps using HTML5, Javascript and CSS. Building applications for each device–iPhone, Android, Windows Mobile and more–requires different frameworks and languages.
I did some spelunking on how Cordova iOS passes messages to the WebView. This is how to pass a message from iOS to JavaScript.
The UIWebView
Class has a method called stringByEvaluatingJavaScriptFromString
.
If you look in some files in the iOS Cordova Project, they are passing the JavaScript as a string that is to be executed to that function, e.g. CDVPlugin.m.
I do not know if iOS writes a new DOM node (something like <script>alert('from iOS');</script>
) or it executes the JavaScript through a special hook in Safari. I believe the later, in that, the documentation referenced above says:
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.
I don't know how they could actually impose those limitations without some special access to that UIWebView's internal state, so I doubt they are just inserting a new DOM node.
I am not entirely sure, but here is the information tutorial. It is a good place to start.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With