Phonegap (now called Cordova) is like writing an HTML5 web page, adding javascript, packaging it, installing it on your phone, and having access to all the features and hardware on your phone. Is javascript so powerful? I have been engaged in WEB development for a long time. According to my understanding, the functions of WEB pages and scripts inside are weak and subject to security restrictions everywhere. For example, javascript has cross-domain access problems, and even in some browsers, it is difficult to copy and paste scripts.
So how does PhoneGap provide scripted access to phone hardware?
Recently, I have been working on a small project for Android using PhoneGap. Take Android as an example to talk about my understanding:
Phonegap for Android project is essentially an Android project
Phonegap web pages and scripts should be placed in the Android project \ Assets folder. That is to say, they should be attached to the Android project, packaged and published as a complete Android APK. So phoneGap for Android is, in essence, an Android app, at best, a kind of special Android app.
Phonegap is the same for other mobile platforms. For example, using PhoneGap to develop IOS applications, you also need to build an IOS development environment and put these pages and scripts into the IOS project. The so-called cross-platform, is the theory, the web page, script only write a copy, and then copy, paste to each platform of the project inside it.
2. Android and IOS have a built-in browser (WebView) on which PhoneGap applications run. Phonegap encapsulates and extends webViews on different mobile platforms, thus enabling scripting and HTML5 to access mobile hardware.
As HTML is just some simple markup, but under the interpretation and support of the browser, it presents a colorful dazzling effect, JS, HTML itself does not have much powerful ability, just because of WebView, mobile phone platform support, so it can play a powerful effect.
————————————-
2019.12.10
A WebView is not the same as a browser. Webviews provide an API Bridge between JS and the underlying API. It’s a container. What PhoneGap(Cordova) can do is access the WebView.
————————————-
3. Phonegap is just an interface to access the hardware of the phone, which is the responsibility of the phone platform, so it can be cross-platform
Phonegap is an intermediary. For developers, it provides a unified API to call, and on the other end, different packages are developed for different mobile platforms. Phonegap, which we built during development, references jar packages for different mobile platforms. Of course, these packages, I guess, call the various apis of the mobile platform for various kinds of phone access, phoneGap itself does not directly access the phone. So it can be cross-platform.
Therefore, in theory, I don’t think the phoneGap hybrid should be any different from the native model in terms of access to the phone’s hardware.