Beginning with Apache Cordova

前端 未结 3 1512
南旧
南旧 2021-02-09 10:55

I have just donwloaded Apache Cordova and it seems like there are platform specific versions. Do I have to code for a specific platform before porting it to another? Is it possi

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-09 11:31

    I think that there is a slight gap in your understanding of Cordova. Cordova is used to build hybrid mobile applications. Hybrid means that your application is basically a standard web site built with HTML/CSS/JavasScript, but it has access to native device functionality. Usually when you are building a regular website with JavaScript, you cannot do certain things without working directly in the native code, like taking a picture or going through the Contacts on the phone. However, Cordova allows you to access these native functions just from the JavaScript! And you never have to touch the native code! So you will build one application in HTML/JavaScript/CSS (one uniform codebase!), and after you go through the build process, will have multiple application files, one for each native platform that you "built" it for.

    Yes, one major benefit of using Cordova is that you can easily create multiplatform apps. What you do is first create your application in HTML/JavaScript - when you need to use a native API, you can just call the appropriate Cordova JavaScript API - this API is common across all of the platforms, meaning that calling say cordova.someAPI.doCoolDeviceOnlyThingThatBrowsersCantDoYet(parameter) will expect the same parameters no matter what device the user is using. Your built Cordova app will then call the equivalent native functionality, no matter which OS the app was built for.

    In order to create an app for, say, iOS and Android, you will need to set up the appropriate build tools for both platforms. Then what you will do is import your HTML/Javascript files that make up your application into these tools and "build" the native app, which will wrap your HTML/JavaScript in native code, add the device specific Cordova code (usually in the form of something like cordova.jar on Android) and create the downloadable package that you can then publish to app stores. This process of "compiling" your app to the multiple platforms can be a pain, but thankfully there is an automated service that can help, so check out PhoneGap build while it's still free.

    You should be able to get started building apps with just your favorite HTML editor, the Ripple emulator, and the Cordova API reference guides. However, you will probably want a real device to test in and build your app with, so you probably will have to set up at least one native environment (like Eclipse with the Android ADT and the appropriate cordova.js file.) (The cordova.js file is very similar between platforms, except for when there are differences between platforms, like in the bridge that handles communication between JavaScript and the native code.)

    Hopefully I have answered all of your questions - good luck!

提交回复
热议问题