UpdateManager.applyUpdate
解释: 当新版本下载完成,调用该方法会强制当前小程序应用上新版本并重启
方法参数
无
示例
在开发者工具中预览效果
扫码体验
请使用百度APP扫码
代码示例
-
<view class="card-area"> <view class="top-description border-bottom">applyUpdate</view> <button type="primary" bindtap="updateTap">button</button> </view>
-
Page({ updateTap() { const updateManager = swan.getUpdateManager(); updateManager.onCheckForUpdate(function (res) { // 请求完新版本信息的回调 console.log("res", res.hasUpdate); if(!res.hasUpdate){ swan.showModal({ title: '更新提示', content: '无可用更新版本', }); } }); updateManager.onUpdateReady(function (res) { swan.showModal({ title: '更新提示', content: '新版本已经准备好,是否重启应用?', success(res) { if (res.confirm) { // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 try { updateManager.applyUpdate(); } catch(e) { swan.showToast({ title: '更新提示', content: '应用新版本失败' }); } } } }); }); }});
Bug & Tip
undefined;当新版本下载完成时,若接口调用失败,会抛出一个标准的Error对象。
