在onLaunch生命周期里面調(diào)用??
?onLaunch?()?{
?????this.UpdateManager ()
??},
??//版本更新提示
????UpdateManager?()?{
?????????if?(?uni.canIUse('getUpdateManager')?)?{
??????????const?updateManager?=?uni.getUpdateManager();
? ? ? ?updateManager.onCheckForUpdate?(?res?=>?{
? ? ? ? ? if?(?res.hasUpdate?)?{
????????????????????wx.showModal({
??????????????????????title:?'更新提示',
??????????????????????content:?'檢測(cè)到新版本,是否下載新版本并重啟小程序?',
??????????????????????success:?function?(res)?{
????????????????????????if?(res.confirm)?{
??????????????????????????//2.?用戶確定下載更新小程序,小程序下載及更新靜默進(jìn)行
??????????????????????????downLoadAndUpdate(updateManager)
????????????????????????}?else?if?(res.cancel)?{
??????????????????????????//用戶點(diǎn)擊取消按鈕的處理,如果需要強(qiáng)制更新,則給出二次彈窗,如果不需要,則這里的代碼都可以刪掉了
??????????????????????????wx.showModal({
????????????????????????????title:?'溫馨提示~',
????????????????????????????content:?'本次版本更新涉及到新的功能添加,舊版本無(wú)法正常訪問(wèn)的哦~',
????????????????????????????showCancel:?false,//隱藏取消按鈕
????????????????????????????confirmText:?"確定更新",//只保留確定更新按鈕
????????????????????????????success:?function?(res)?{
??????????????????????????????if?(res.confirm)?{
????????????????????????????????//下載新版本,并重新應(yīng)用
????????????????????????????????downLoadAndUpdate(updateManager)
??????????????????????????????}
????????????????????????????}
??????????????????????????})
????????????????????????}
??????????????????????}
????????????????????})
????????????}
??????????})
??????}?else?{
????//?如果希望用戶在最新版本的客戶端上體驗(yàn)?zāi)男〕绦颍梢赃@樣子提示
????????uni.showModal({
??????????title:?'提示',
??????????content:?'當(dāng)前微信版本過(guò)低,無(wú)法使用該功能,請(qǐng)升級(jí)到最新微信版本后重試。'
????????})
??????}
????},