首页 > 其他 > 详细

hbuilder 热更新

时间:2019-05-08 17:17:30      阅读:238      评论:0      收藏:0      [点我收藏+]

记录下Hbuilder做热更新的功能。

首先是获取本地的版本与服务器的版本对比。服务器的版本大于本地的版本才进行更新。获取本地版本的方法

    plus.runtime.getProperty(plus.runtime.appid, data => {
        let version = data.version ///获取本地的版本。
    });

然后下载服务器的wgt更新文件方法并安装

    download() {
      // 更新文件 wgt 文件地址
      var wgtUrl = "http://10.10.10.76:8081/H5347043D.wgt";
      plus.nativeUI.showWaiting("更新ing...");
      plus.downloader
        .createDownload(wgtUrl, { filename: "update" }, (d, status) => {
          if (status == 200) {
            this.install(d.filename); // 下载成功安装
          } else {
            plus.nativeUI.alert("下载wgt失败!");
          }
          plus.nativeUI.closeWaiting();
        })
        .start();
    },
    install(path) {
      // 安装下载 的文件
      plus.nativeUI.showWaiting("安装wgt文件...");
      plus.runtime.install(
        path,
        {},
        function() {
          plus.nativeUI.closeWaiting();
          console.log("安装wgt文件成功!");
          plus.nativeUI.alert("应用资源更新完成!", function() {
            plus.runtime.restart();
          });
        },
        function(e) {
          plus.nativeUI.closeWaiting();
          console.log("安装wgt文件失败[" + e.code + "]:" + e.message);
          plus.nativeUI.alert("安装wgt文件失败[" + e.code + "]:" + e.message);
        }
      );
    }
npm run build

打包后在Hubilder里面选择发行--->制作移动App资源升级包。打包出来 的WGT文件 放在服务器就可以了

hbuilder 热更新

原文:https://www.cnblogs.com/huzhuhua/p/10832675.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!