当前位置: 首页 > 工具软件 > push-plugin > 使用案例 >

cordova 热更新插件 cordova-hot-code-push-plugin

章心水
2023-12-01

入门 : https://www.jianshu.com/p/322e2801b4b6   

https://www.jianshu.com/p/55fd5e9f96ea

https://yq.aliyun.com/articles/659463

config.xml中

<chcp>

<auto-download enabled="false" />

<auto-install enabled="true" />

<native-interface version="2" />

<config-file url="http://192.168.0.208:58277/19liangpin_app/www/chcp.json" />

</chcp>

关于更新www下的内容

auto-download enabled =true时,无需js调用fetchUpdate 即可自动下载更新,否则必须调用

auto-install enabled="true" 时,无需js调用即可自动下载更新

关于更新app本身,如果需要升级,就会给js报错,并且不会升级www中的内容,可以监听chcp_updateLoadFailed事件

document.addEventListener('chcp_updateLoadFailed', this.onUpdateLoadError, false);

也可以手动调用fetchUpdate时指定回调函数

  chcp.fetchUpdate((error, data) => { 
                   if (error) { 
                    console.log('--更新版本异常,或其他错误--', error.code, error.description);
                    if (error.code === -2) {
                      var dialogMessage = '有新的版本是否下载';
                      //调用升级提示框 点击确认会跳转对应商店升级
                      chcp.requestApplicationUpdate(dialogMessage, null, null); 

                    }
                  }

注意:  android调用requestApplicationUpdate,会从app现有的chcp.json(并非最新版的chcp.json) 中读android_identifier,并下载,android_identifier 必须以http或https开头

 类似资料: