export default { checkVersionUrl:function(){ const systemInfo = uni.getSystemInfoSync(); const platform = systemInfo.platform; //appName 宿主APP名称 字节跳动小程序 //AppPlatform App平台 QQ小程序 //host 宿主平台 百度小程序 //app 当前运行的客户端 支付宝小程序 console.log("systemInfo.appName" + systemInfo.appName) console.log("systemInfo.AppPlatform" + systemInfo.AppPlatform) console.log("systemInfo.host" + systemInfo.host) console.log("systemInfo.app" + systemInfo.app) console.log("systemInfo.SDKVersion" + systemInfo.SDKVersion) console.log("systemInfo.swanNativeVersion" + systemInfo.swanNativeVersion) let versionCode = plus.runtime.app.versionCode console.log("plus.runtime.app.versionCode" + plus.runtime.app.versionCode) console.log("plus.runtime.app.versionCode" + plus.runtime.app.versionCode) let checkVersionurl = "" // 检测更新地址 let runAppFlag = true //运行平台判断 if(systemInfo.appName == "微信小程序") { runAppFlag = false } if(runAppFlag) { uni.request({ url: checkVersionurl, //仅为示例,并非真实接口地址。 data: { versionCode: versionCode, platform: platform }, header: { //'custom-header': 'hello' //自定义请求头信息 }, success: (res) => { console.log(res.data); let downloadUrl = res.data; if (platform == "android") { // 安装下载的apk文件 let dtask = plus.downloader.createDownload(downloadUrl, {}, function(d, status) { if (status == 200) { // 下载成功 let path = d.filename plus.runtime.install(path) console.log(d.filename) } else { //下载失败 alert("Download failed: " + status) } }) dtask.start() // dtask.addEventListener("statechanged", function(task, status) { // switch (task.state) { // case 1: // 开始 // res.change({ // progressValue:0, // progressTip:"准备下载...", // progress: true // }); // break; // case 2: // 已连接到服务器 // res.change({ // progressValue:0, // progressTip:"开始下载...", // progress: true // }); // break; // case 3: // const progress = parseInt(task.downloadedSize / task.totalSize * 100); // if(progress - lastProgressValue >= 2){ // lastProgressValue = progress; // res.change({ // progressValue:progress, // progressTip: "已下载" + progress + "%", // progress: true // }); // } // break; // } // }); } else { //url在appstore的地址 plus.runtime.openURL(url) } } }); } } }