1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| const versionMCompare = () => { let _this = this; var urlfun = "自己的接口" plus.screen.lockOrientation('portrait-primary'); console.log("onLaunch锁定屏幕方向") plus.runtime.getProperty(plus.runtime.appid, function(info) { getApp().globalData.editionnum = info.version; uni.request({ url: urlfun, method: "POST", data: { "appid": plus.runtime.appid, "version": plus.runtime.version, "system": uni.getStorageSync('systemname'), "editionnum": info.version, }, success: (res) => { console.log("--返回状态--" + JSON.stringify(res.data)); var data = res.data; var status = data.status; if (status == 200) { checkVersionToLoadUpdate(info.version, data); } else { uni.showToast({ title: data.msg, duration: 1500 }); } } }); }) }
const downloadVersion = (server_version, data) =>{ if (server_version !== data.edition) { if (plus.networkinfo.getCurrentType() != 3) { uni.showToast({ title: '有新的版本发布,检测到您目前非Wifi连接,为节约您的流量,程序已停止自动更新,将在您连接WIFI之后重新检测更新', mask: true, duration: 8000, icon: "none" }); return; } else { uni.showModal({ title: "版本更新", content: '有新的版本发布,检测到您当前为Wifi连接,是否立即进行新版本下载?', confirmText: '立即更新', cancelText: '稍后进行', success: function(res) { if (res.confirm) { uni.showToast({ icon: "none", mask: true, title: '有新的版本发布,检测到您目前为Wifi连接,程序已启动自动更新。新版本下载完成后将自动弹出安装程序。', duration: 5000, }); var downloadApkUrl = data.uplodurl; var dtask = plus.downloader.createDownload(downloadApkUrl, {}, function(d, status) { if (status == 200) { plus.runtime.install(plus.io.convertLocalFileSystemURL(d .filename), {}, {}, function(error) { uni.showToast({ title: '安装失败', duration: 1500 }); }) } else { uni.showToast({ title: '更新失败', duration: 1500 }); } }); dtask.start(); } else if (res.cancel) { console.log('稍后更新'); } } }); } } }
export { versionMCompare, downloadVersion }
|