Score
0
Watch 7 Star 9 Fork 0

五牛 / cordova-hot-code-pushJavaScriptMIT

Join us
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
实现基于cordova的app自动更新的插件 spread retract

http://git.oschina.net/wuniu55/cordova-hot-code-push

Clone or download
Loading...
README.md

Cordova Hot Code Push Plugin

This plugin provides functionality to perform automatic updates of the web based content in your application. Basically, everything that is stored in www folder of your Cordova project can be updated using this plugin.

When you publish your application on the store - you pack in it all your web content: html files, JavaScript code, images and so on. There are two ways how you can update it:

  1. Publish new version of the app on the store. But it takes time, especially with the App Store.
  2. Sacrifice the offline feature and load all the pages online. But as soon as Internet connection goes down - application won't work.

This plugin is intended to fix all that. When user starts the app for the first time - it copies all the web files onto the external storage. From this moment all pages are loaded from the external folder and not from the packed bundle. On every launch plugin connects to your server (with optional authentication, see fetchUpdate() below) and checks if the new version of web project is available for download. If so - it loads it on the device and installs on the next launch.

As a result, your application receives updates of the web content as soon as possible, and still can work in offline mode. Also, plugin allows you to specify dependency between the web release and the native version to make sure, that new release will work on the older versions of the application.

Is it fine with App Store? Yes, it is... as long as your content corresponds to what application is intended for and you don't ask user to click some button to update the web content. For more details please refer to this wiki page.

热更新插件简介: 简单来说,此插件可以让用户在重新下载app安装包的条件下更新app内容(www下的所有文件都可以,但是www外有关的东西,比如plugins,比如config.xml不可以更新到)

Supported platforms 支持平台

  • Android 4.0.0 or above.
  • iOS 7.0 or above. Xcode 7 is required.

Installation 安装条件

This requires cordova 5.0+ (current stable 1.5.2)

cordova plugin add cordova-hot-code-push-plugin

It is also possible to install via repo url directly (unstable)

cordova plugin add http://git.oschina.net/wuniu55/cordova-hot-code-push.git

At the end of the installation plugin will recommend you to install Cordova Hot Code Push CLI client. This client will help you to:

  • easily generate necessary configuration files;
  • launch local server to listen for any changes in the web project and deploy new version immediately on the app.

Of course, you can use this plugin without the CLI client, but it will make your life easier.

快速上手

平台:android,ios 准备工作:项目已经创建,并能成功打包,国内需安装了cnpm 功能:可以在不更新安装app的情况下更新www目录下的文件 核心步骤: #1、安装热更新插件 d: cd d:\stat\test1 cordova plugin add http://git.oschina.net/wuniu55/cordova-hot-code-push.git #2、安装命令行工具 cordova-hot-code-push-cli cnpm install -g cordova-hot-code-push-cli 作用:提供命令 cordova-hcp server(其实不需要) 和 cordova-hcp build,生成 [project]/www/chcp.json [project]/chcp.manifest 2个配置文件 #3、用cordova-hot-code-push-cli创建配置 开两个命令窗口,都进入到项目的根目录,第一个窗口敲入命令:cordova-hcp server,开启服务后不要关闭,第二个窗口敲入cordova build,此时上面所说的3个配置文件应都已生成,2个配置文件的属性及作用如下: www/chcp.json { "autogenerated": true, "release": "2017.01.05-01.15.10", "content_url": "http://xxx.xxx.com/app", "update": "now" } 看字面意思即可得知,autogenerated应指是否自动更新,release是指www文件夹的更新时间,content_url是服务器www的路径,update是指更新方式,now是下载立即更新,start是下载完后下次启动再更新。 本地的chcp.json存储本地的更新版本时间,服务器的chcp.json存储服务器的更新版本时间,热更新插件会自动比对本地chcp.json和服务器chcp.json的差异,如果发现服务器版本最新,则开启热更新,否则,不更新。 后两条不知是否必须 www/chcp.manifest [ { "file": "chcpbak.h", "hash": "130c7f0a41085754a13c2fcd4346c093" }, { "file": "css/business/add_bank.css", "hash": "e45d535d17e08db51d0ff544771a3cbb" }, //......更多文件...... ] 每个文件名字和修改时间信息组成对象,www的所有文件信息组成的组列表,file对应文件路径 ,hash是文件修改时间加密的字符串,即只有当文件修改了,hash值才会变~ #4、检查config.xml,确保有配置字段 输入图片说明 url的值对应服务器的chcp.json,

#5、APP打包 sudo ionic build ios xcode打包 此时,app已经具备热更新的条件,只需匹配服务端信息进行热更新处理 #6、热更新 打包后,把www下的文件全部放入服务器的更新地址,比如此处要放到http://xxx.xxx.com/app路径下。 需要对www下文件进行更新时,先cd,进入项目路径,修改调试代码,完毕后,执行cordova-hcp build,此时会更新www/chcp.json , www/chcp.manifest两个文件。把chcp.json,chcp.manifest和本次更新的代码上传到服务器更新地址上,打开APP,即会更新(可能要退一次才更新,如果进入页面完成后又重载了一次页面,排除代码的问题,那就是热更新成功了!)

总结: 真正核心的配置还是config.xml、www/chcp.json、www/chcp.manifest,分别配置:服务器版本验证文件、本地版本验证文件、本地/远程文件状态信息。

注释: mac环境下配置基本都要在命令行最前面加sudo ,表示使用管理员权限。 每次更新都要把更新的所有文件都上传上去,否则文件信息跟chcp.manifest的内容不匹配,会导致不更新

Comments ( 0 )

Sign in for post a comment

JavaScript
1
https://gitee.com/wuniu55/cordova-hot-code-push.git
git@gitee.com:wuniu55/cordova-hot-code-push.git
wuniu55
cordova-hot-code-push
cordova-hot-code-push
master

Help Search

205735 778617b6 1899542 205747 347fc4a1 1899542