Getting Started with Cordova - Overview - Architecture

Overview

Apache Cordova is an open source mobile development framework. Allows you to do cross-platform development with standard web technologies - HTML5, CSS3 and JavaScript. The specific execution of the application on each platform is encapsulated, and relies on standard API bindings to access the functions of each device, such as: sensors, data, network status, etc.

People using Apache Cordova:

  • Mobile app developers who want to extend an app's usage platform without reimplementing it through each platform's language and toolset.

  • A web developer who wants to package and deploy their own web App and distribute it to various app store portals.

  • Mobile app developers, interested in mixing native app components with a WebView (a special browser window) that can access the device A-level PI, or you want to develop a plugin interface between native and WebView components.

Architecture

Here are several components of a cordova application. The image below is a high-level view of the cordova application architecture.


WebView

Cordova-enabled WebView can provide a complete user interface to the application. On some platforms, it can also be used as a component for large, hybrid applications that mix with WebView and native application components. (See Embedding WebViews for details.)

Web App

This is where your application code lives. The implementation of the application is through the web page. The default local file name is index.html . This local file applies CSS, JavaScript, images, media files and other resources required for operation. The application executes in a WebView that wraps the native application that you distribute to the app stores.

This container contains a very important file -  the config.xml  file, which provides important information about the App and specific parameters to affect the work of the App, such as whether to respond to changes in direction.

plugin

插件是Cordova生态系统的重要组成部分。他提供了Cordova和原生组件相互通信的接口并绑定到了标准的设备API上。这使你能够通过JavaScript调用原生代码.

Apache Cordova项目维护着一组插件叫做核心插件。这些核心插件可以让你的应用程序访问设备功能,比如:电源,相机,联系人等。

除了核心插件,这里还有一些第三方插件他们提供了一些附加功能,但这些功能不一定在每个平台都能用。你可以搜索Cordova插件使用插件搜索或者npm。你也可以开发自己的插件,像 插件开发指南描述的那样。插件是必要的,例如Cordova和自定义原生组件之间通信。

注意:当你创建一个Cordova项目它不存在任何插件。这是新的默认行为。任何你需要的组件,哪怕是核心组件,你也必须明确添加。

Cordova不提供任何UI部件和MV框架。Cordova只提供运行环境。如果你想使用UI部件或者MV框架,你需要选择他们并包含在你的应用程序中。

开发工作流

Cordova提供两个基本的工作流用来创建移动App。虽然你经常使用两种不同工作流完成同样的任务,但是他们之间是有各自优势的:

  • 跨平台(CLI)的工作流:如果你想你的App运行在尽可能多的移动操作系统,那么就使用这个工作流,你只需要很少的特定平台开发。 这个工作流围绕这'cordova'CLI(命令行)。CLI是一个高级别的工具,他允许一次构建多个平台的项目,抽象了很多功能性的低级别shell脚本。CLI把公用的web资源复制到每个移动平台的子目录,根据每个平台做必要的配置变化,运行构建脚本生成2进制文件。CLI统一也提供通用接口,将插件应用在app中。如果要入门可以按照 创建你的第一个App指南中的步骤来 。除非你有一个以平台为中心的工作流,否则建议你使用跨平台工作流。

  • 平台为中心的工作流:如果你专注于构建单独平台的App或者需要需要在底层修改它那么就使用这个工作流吧。你需要使用这种方法,如果你需要你的App混合原生组件和基于Web的Cordova组件, 正如 嵌入WebView讨论的。作为一个经验法则,如果你需要修改SDK中的项目那么使用这个工作流。 这个工作流依靠一组低级别的shell脚本,他们是给每个支持平台量身定做的,还有一个单独的Plugman工具允许你添加插件。 虽然你可以使用这个工作流构建跨平台应用,但通常这是非常困难的,因为缺乏高基本的工具,意思就是是单独的构建生命周期并且插件修改需要对每一个平台进行。

当你第一次开始,跨平台工作流创建App可能是最容易的,像创建你的第一个App中描述的那样。然后,你可以切换到以平台为中心的工作流,如果你需要更好的控制SDK提供的功能。

注意: 一但你从以CLI为中心的工作流切换到一个围绕特定平台SDK和shell工具的工作流中,你就不可能返回了。 CLI维护着一套通用的跨平台源代码,每个特定平台构建都需要使用他而不是特定平台的源码。为了保护你对特定平台资产的修改,你需要切换到以平台为中心的脚本工具,他忽略跨平台的源码,转而依靠特定平台的源码。

安装Cordova

安装Cordova会因你依靠的工作流不同而不同:

在安装完Cordova之后,建议你查看平台开发部分来进行移动平台开发。 同时建议你查看隐私指南 和 安全指南.

文章来源于http://cordova.axuer.com/docs/zh-cn/latest/guide/overview/index.html


联系我们

QQ:250187715 
QQ群:390736068



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324517855&siteId=291194637