uni-halo/utils/update.js
2022-12-06 15:08:29 +08:00

48 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 检查微信小程序更新
*/
export const CheckWxUpdate = (useTip = false) => {
if (uni.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager();
updateManager && updateManager.onCheckForUpdate((res) => {
if (res.hasUpdate) {
updateManager.onUpdateReady(() => {
uni.showModal({
title: '更新提示',
content: '新版本已经准备就绪是否需要重新启动应用',
success: (res) => {
if (res.confirm) {
uni.clearStorageSync() // 更新完成后刷新storage的数据
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(() => {
uni.showModal({
title: '已有新版本上线',
content: '小程序自动更新失败请删除该小程序后重新搜索打开哟~~~',
showCancel: false
})
})
} else {
if (useTip) {
//没有更新
uni.showToast({
icon: 'none',
title: '已经是最新版本'
})
}
}
})
} else {
uni.showModal({
title: '提示',
content: '当前微信版本过低无法使用该功能请更新到最新的微信后再重试',
showCancel: false
})
}
}