zoukankan      html  css  js  c++  java
  • dcloud资源升级方式更新app

    var wgtVer = null;
    plus.runtime.getProperty(plus.runtime.appid, function(inf) {
                            wgtVer = inf.version;
                            console.log("当前应用版本:" + wgtVer);
    
                            // 检测更新
                            var checkUrl = getAbsUrl("update/check");
    
                            function checkUpdate() {
                                plus.nativeUI.showWaiting("检测更新...");
                                var xhr = new XMLHttpRequest();
                                xhr.onreadystatechange = function() {
                                    switch(xhr.readyState) {
                                        case 4:
                                            plus.nativeUI.closeWaiting();
                                            if(xhr.status == 200) {
                                                console.log("检测更新成功:" + xhr.responseText);
                                                var newVer = xhr.responseText;
                                                if(wgtVer && newVer && (wgtVer != newVer)) {
                                                    // 下载升级包
                                                    newVer = newVer.replace('.', '');
                                                    var wgtUrl = getAbsUrl("qr/" + newVer + ".wgt");
    
                                                    plus.nativeUI.showWaiting("下载wgt文件...");
                                                    plus.downloader.createDownload(wgtUrl, {
                                                        filename: "_doc/update/"
                                                    }, function(d, status) {
                                                        if(status == 200) {
                                                            console.log("下载wgt成功:" + d.filename);
                                                            // 安装wgt包
                                                            var path = d.filename;
                                                            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);
                                                            });
                                                        }
                                                        plus.nativeUI.closeWaiting();
                                                    }).start();
                                                }
                                            } else {
                                                console.log("检测更新失败!");
                                            }
                                            break;
                                        default:
                                            break;
                                    }
                                }
                                xhr.open('POST', checkUrl);
                                xhr.send();
                            }
                            
                            checkUpdate();
                        });
     

    下面是整包更新的代码:

    mui.getJSON(getAbsUrl('update/check'), {
                            "appid": plus.runtime.appid,
                            "version": plus.runtime.version
                        }, function(data) {
                            if(data.status) {
                                plus.nativeUI.confirm(data.note, function(event) {
                                    if(0 == event.index) {
                                        plus.runtime.openURL(data.url);
                                    }
                                }, data.title, ["立即更新", "取  消"]);
                            }
                        });

     参考:http://ask.dcloud.net.cn/article/182

  • 相关阅读:
    Oracle10g服务启动命令
    Linux系统添加永久静态路由的方法
    搭建YUM仓库与定制RPM包
    LVS简介
    【Linux】先添加一块磁盘制作LVM卷并进行分区挂载
    函数部分
    Python中if __name__ == "__main__": 的作用 (整理转自Arkenstone) --感谢!
    python语言基础笔记
    部分示例程序
    转,关于游标
  • 原文地址:https://www.cnblogs.com/slmk/p/6970347.html
Copyright © 2011-2022 走看看