微信小程序更新提醒(uniapp)
在uniapp中存在一个API,updateManager,用于管理小程序更新。
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
| import { onLaunch } from '@dcloudio/uni-app'
const updateApp = ()=>{ const updateManager = uni.getUpdateManager(); updateManager.onCheckForUpdate((res)=>{ console.log(res.hasUpdate); }) updateManager.onUpdateReady(function (res) { uni.showModal({ title: '更新提示', content: '新版本已经准备好,是否重启应用?', success(res) { if (res.confirm) { updateManager.applyUpdate(); } else if (res.cancel) { console.log('用户点击取消,不更新'); } } }); }); updateManager.onUpdateFailed(function (res) { uni.showModal({ title: '已经有新版本了哟~', content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~', }) }); } onLaunch(()=>{ updateApp() })
|
web应用更新提醒
APP更新提醒