以Promise风格调用: 支持
强制小程序重启并使用新版本。在小程序新版本下载完成后(即收到 onUpdateReady 回调)调用。
属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| success | function | 否 | 接口调用成功的回调函数 | |
| fail | function | 否 | 接口调用失败的回调函数 | |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
属性 | 类型 | 说明 |
|---|---|---|
| errMsg | string |
// 获取全局唯一的版本更新管理器
const updateManager = xhs.getUpdateManager();
// 监听新版本下载完成的回调
updateManager.onUpdateReady(() => {
console.log('新版本已下载完成');
// 提示用户是否重启以应用新版本
xhs.showModal({
title: '更新提示',
content: '新版本已准备好,是否重启应用?',
success: (result) => {
if (result.confirm) {
// 用户确认后,强制小程序重启并使用新版本
updateManager.applyUpdate({
success: () => {
console.log('小程序已成功重启并使用新版本');
},
fail: (err) => {
console.error('重启失败:', err.errMsg);
},
complete: () => {
console.log('applyUpdate 调用结束');
}
});
}
}
});
});