从Apache Cordova开始 [英] Beginning with Apache Cordova

查看:104
本文介绍了从Apache Cordova开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚加载了Apache Cordova,似乎有平台特定的版本。在将其移植到另一个平台之前,我必须为特定平台编写代码吗?是否可以创建一个多平台项目?我是否正确理解我应该开始工作的方式?



这也是Apache Cordova首页说的。


因为这些JavaScript API在多个
设备平台上是一致的,并且基于web标准,所以应用程序应该
可移植到其他设备平台, p>

感谢。

解决方案在你对科尔多瓦的理解有一个微小的差距。 Cordova用于构建混合移动应用程序。混合意味着您的应用程序基本上是使用HTML / CSS / JavasScript构建的标准网站,但它可以访问本机设备功能。通常当您使用JavaScript构建常规网站时,无法直接在本机代码中进行某些操作,例如拍照或通过手机上的联系人。但是,Cordova允许您从JavaScript访问这些本机函数!你永远不必触摸本地代码!因此,您将在HTML / JavaScript / CSS(一个统一的代码库!)中构建一个应用程序,并且在您完成构建过程后,将有多个应用程序文件,每个为您构建的原生平台。



是的,使用Cordova的一个主要优点是您可以轻松创建多平台应用程序。您所做的是首先使用HTML / JavaScript创建应用程序 - 当您需要使用本机API时,您只需调用相应的 Cordova JavaScript API - 此API在所有平台中都很常见,这意味着调用说 cordova.someAPI.doCoolDeviceOnlyThingThatBrowsersCantDoYet(parameter)参数,无论用户正在使用什么设备。



为了创建一个应用程序,例如iOS和Android,您的内置Cordova应用程序将调用相应的本机功能,您需要设置适当的构建工具两个平台。然后你会做的是将组成你的应用程序的HTML / Javascript文件导入到这些工具中,并构建本地应用程序,这将在本机代码中包装你的HTML / JavaScript,添加设备特定的Cordova代码例如Android上的cordova.jar),然后创建可下载的软件包,然后发布到应用商店。将您的应用程序编译到多个平台的过程可能会很痛苦,但幸运的是有一个自动化服务可以帮助您,请查看 PhoneGap构建而它仍然是免费的



您应该能够开始构建应用程序,只需使用您最喜欢的HTML编辑器,Ripple仿真器和Cordova API参考指南。但是,你可能需要一个真正的设备来测试和构建你的应用程序,所以你可能需要设置至少一个本机环境(如Eclipse与Android ADT和适当的cordova.js文件。)(cordova .js文件在平台之间非常相似,除非平台之间存在差异,例如在处理JavaScript和本地代码之间的通信的桥梁中。)



希望我已回答了您的所有问题 - 祝您好运!


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 possible to create a multiplatform project? Am I understand correctly the way I should start working?

This is also what the Apache Cordova homepage says.

And because these JavaScript APIs are consistent across multiple device platforms and built on web standards, the app should be portable to other device platforms with minimal to no changes.

Thanks.

解决方案

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!

这篇关于从Apache Cordova开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆