7 Star 12 Fork 2

五牛 / cordova-hot-code-push

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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的内容不匹配,会导致不更新

The MIT License (MIT) Copyright (c) 2015 Nordnet Bank AB Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

实现基于cordova的app自动更新的插件 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
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

搜索帮助

14c37bed 8189591 565d56ea 8189591