前端攻城师
前端攻城师
  • 发布:2017-10-25 17:48
  • 更新:2019-08-14 17:10
  • 阅读:2404

【分享】静默更新

分类:HTML5+
/*  
* 静默更新插件  
* 直接appUpadata.init()去调用此插件  
 */  
! function(window, undefined) {  
    var appUpdata = window.appUpdata = {  
        init: function() {  
            var that = this;  
            if(plus) {  
                plus.runtime.getProperty(plus.runtime.appid, function(inf) {  
                    var wgtVer = inf.version;  
                    bpAjax("此处为利用ajax请求服务器的静默更新版本,后台返回一个下载地址", {  
                        version: plus.runtime.version,  
                        resVersion: wgtVer  
                    }, function(d) {  
                        that.downFn(d.data.url);  
                    }, function(d) {  
                        //mui.toast(d.info)  
                    }, 1, "版本")  
                });  

            }  
        },  
        // 下载文件  
        downFn: function(wgtUrl) {  
            var that = this;  
            if(plus) {  
                plus.downloader.createDownload(wgtUrl, {  
                    filename: "_doc/update/"  
                }, function(d, status) {  
                    if(status == 200) {  
                        that.installWgt(d.filename);  
                    } else {  
                        console.log("下载版本失败!");  
                    }  
                }).start();  
            }  
        },  
        // 安装文件  
        installWgt: function(path) {  
            if(plus) {  
                plus.runtime.install(path, {}, function() {  
                    console.log("安装版本成功!");  
                }, function(e) {  
                    console.log("安装版本失败[" + e.code + "]:" + e.message);  
                });  
            }  
        }  
    }  
}(window)
0 关注 分享

要回复文章请先登录注册

熊二的二

熊二的二

mark
2019-08-14 17:10
JFry

JFry

这个好像不是静默安装 还是会弹出apk安装界面给你确认
2019-01-24 17:36
前端攻城师

前端攻城师 (作者)

回复 很好爱爱啊 :
你可以看下这个,https://ask.dcloud.net.cn/article/12872
2017-10-27 11:39
很好爱爱啊

很好爱爱啊

Ajax的样式能发下吗
2017-10-25 23:08