ionic 3 热更新 Hot Code Push

  最近用ionic 3 做的app业务做的差不多了,突然想到以后app如果有更新该怎么搞?想到我们的app后期更新应该不大,,最多就是改改bug和增加下用户体验,如果只有一些小的更新,然后提交各个应用商店,需要长时间的审核...鉴于我们制作android平台,再而我们用的技术是前端3大件:html,css和js,因此我计划用热更新来搞.

  ionic热更新有两个插件:

  这两篇教程写的已经非常详细了,我感觉我都没有写的必要了.我采用第二个插件完成的我的需求,主要原因是:2个插件都支持远程服务器托管你的更新,你只需注册远程认证,通过命令行输入验证并且上传到远程服务器,来进行更新.但是第二个插件支持手动更新资源,将文件放在自己的服务器.具体采用哪种方式实现热更新取决于你的喜好了.

  下面我来记录我在使用中遇到的问题:

  在安装插件的时候

han@ubuntu:~/project/zero_app$ ionic cordova plugin add cordova-hot-code-push
> cordova plugin add cordova-hot-code-push --save
Error: Not found : cordova-hot-code-push
[ERROR] An error occurred while running subprocess cordova.
        
        cordova plugin add cordova-hot-code-push --save exited with exit code 1.
        
        Re-running this command with the --verbose flag may provide more information.

han@ubuntu:~/project/zero_app$ cordova plugin add cordova-hot-code-push-plugin
Installing "cordova-hot-code-push-plugin" for android
Installing dependency packages: 

  ionic官方文档中提供的方法不行,使用 cordova plugin add cordova-hot-code-push-plugin 命令就可以了.

  更改更新策略

  我采用了教程默认的 now 方式,但是正式版肯定不能是 now ,我想用 cordova-hot-code-push-cli 插件来修改,我没找到解决方法,只能使用最原始的方法,使用 cordova-hcp init 重新生成一份配置:

  

han@ubuntu:~/project/zero_app$ cordova-hcp init
Running init
Please provide: Enter project name (required):  zero app
Please provide: Amazon S3 Bucket name (required for cordova-hcp deploy):  
Please provide: Path in S3 bucket (optional for cordova-hcp deploy):  
Please provide: Amazon S3 region (required for cordova-hcp deploy):  (us-east-1) 
Please provide: IOS app identifier:  cn.swifthealth.zeroapp
Please provide: Android app identifier:  cn.swifthealth.zeroapp
Please provide: Update method (required):  (resume) start
Please provide: Enter full URL to directory where cordova-hcp build result will be uploaded:  http://192.168.1.81:8000/www/
Project initialized and cordova-hcp.json file created.
If you wish to exclude files from being published, specify them in .chcpignore
Before you can push updates you need to run "cordova-hcp login" in project directory

  更新下载,更新安装方式

  为了我开发方便,我使用了自动更新和自动安装,配置在congif.xml中

<chcp>
        <auto-download enabled="true" />
        <auto-install enabled="true" />
        <config-file url="http://192.168.1.81:8000/www/chcp.json" />
</chcp>

  自动安装更新肯定是不合适的,用户会感觉到自己被耍了,好好的使用着,在下次启动的时候跟上次一样了...我会在以后修改为让用户自动选择.

原文地址:https://www.cnblogs.com/hanshuai/p/9429648.html