uni-app自動更新軟件功能實現

<script>
	let that;
	export default {
		data(){
			return{
				version:"1.0.0",//版本號
				platform:"android"//系統平臺
			}
		},
		onLaunch: function() {
			that = this;
			// #ifdef APP-PLUS
				uni.getSystemInfo({
					success: function(res) {
						that.platform = res.platform;// 獲取系統平臺 ios 安卓
						plus.runtime.getProperty(plus.runtime.appid, function(inf) {
							that.version = inf.version;//獲取當前版本號
							//檢測升級
							that.updateApp();
						});
					}
				});
				// 檢測升級
			// #endif
		},
		methods:{
			updateApp(){
				let data = {
					version: that.version,// 系統版本,前端自動獲取
					platform: that.platform// 系統平臺,前端自動獲取(android、IOS)
				};
				let url = 'http://localhost:6060/php/vue/iview/update.php';
				uni.request({
					url: url, //檢查更新的服務器地址
					data: data,
					success: res => {
						if (res.data.code == 1 && res.data.isUpdate) {
							// 提醒用戶更新
							uni.showModal({
								content: res.data.note ? res.data.note : '是否更新',
								success: showResult => {
									if (showResult.confirm) {
										plus.runtime.openURL(res.data.url);//下載最新版本APP
									}
								}
							});
						}
					}
				});
			}
		}
	}
</script>

<style>
	/*每個頁面公共css */
</style>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章