版本校验接口返回

https://192.168.1.113/public/mobile/version

{
	version: 125,
	url: 'https://192.168.1.113/apk/app.apk',
	remark: '本次更新了布拉布拉。。。'
}

自动更新

自动下载APK并安装

Jerry.checkVersion = function(t) {
	$.ajax({
		type: "get",
		url: domain + "/public/mobile/version",
		async: true,
		dataType: "json",
		success: function(rs) {
			plus.runtime.getProperty(plus.runtime.appid, function (info) {
				console.log('当前app版本:' + info.versionCode);
				console.log('最新版本:' + rs.version);
				if(parseInt(rs.version) > parseInt(info.versionCode)) {
					mui.confirm(rs.remark, "更新提示", ['现在更新', '暂不更新'], function(e) {
						if(e.index == 0) {
							var w = plus.nativeUI.showWaiting("正在下载,请等待...", {back: "none"});
							var dtask = plus.downloader.createDownload(rs.url, {}, function(d, status) {
								if(status == 200) {
									w.close();	
									plus.nativeUI.showWaiting("开始安装...");
									plus.runtime.install(d.filename, {}, function() {
										plus.nativeUI.closeWaiting();
										plus.nativeUI.alert("更新完成!", function() {
											plus.runtime.restart();
										});
									}, function(e) {
										plus.nativeUI.closeWaiting();
										plus.nativeUI.alert("安装失败[" + e.code + "]:" + e.message);
									});
								} else {
									mui.alert('下载更新文件失败:' + status);
								}
							});
							dtask.addEventListener("statechanged", function(d, status) {
								var total = parseInt(d.totalSize);
								var cur = parseInt(d.downloadedSize);
								w.setTitle("已下载:" + (cur / (1024 * 1024)).toFixed(2) + "M/" + (total / (1024 * 1024)).toFixed(2) + "M");
							}, false);
							dtask.start();
						}
					});
				} else if(t == 1)  {
					mui.alert("当前已是最新版本");
				}
			});
		}
	});

}

弹出下载APK手动安装

$.ajax({
	type: "get",
	url: domain + "/public/mobile/version",
	async: true,
	dataType: "json",
	success: function(rs) {
		mui.confirm(rs.remark, "更新提示", ['现在更新', '暂不更新'], function(e) {
			if(e.index == 0) {
				plus.runtime.openURL(rs.url);
			}
		});
	}
});

参考资料

uniapp热更新和整包更新
plus.runtime.install 注意权限问题