Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Phonegap work?

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?

like image 903
Apps Avatar asked May 29 '12 18:05

Apps


People also ask

What is PhoneGap and why to use it?

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.

What language does PhoneGap use?

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 tool?

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.


2 Answers

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.

like image 156
weisjohn Avatar answered Oct 03 '22 17:10

weisjohn


I am not entirely sure, but here is the information tutorial. It is a good place to start.

like image 36
John Kane Avatar answered Oct 03 '22 19:10

John Kane