开发者工具和真机测试没有遇到过,但是线上小程序的错误日志分析里,有大量使用2.16基础库的用户这个接口都获取不到UpdateManager这个对象
onLaunch: function (e) {
// 获取更新实例
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
console.log(res.hasUpdate)
})
// 更新提示
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (res) {
if (res.confirm) {
updateManager.applyUpdate()
}
}
})
})
// 更新失败
updateManager.onUpdateFailed(function () {
wx.showToast({
title: '新版本下载失败,请重启应用',
icon: 'none'
})
})
}
因为错误日志都出现在updateManager.onCheckForUpdate,基本可以断定是冷启动时wx.getUpdateManager()偶现失效,错误日志如下:
/**
* Andorid
* 客户端版本号
* 8.0.2 86.67%
* 8.0.1 13.33%
* 基础库2.16.0 100%
*
**/
Cannot read property \'onCheckForUpdate\' of undefined
TypeError: Cannot read property \'onCheckForUpdate\' of undefined
at Oe.checkAppUpdate (https://app.js:35:19)
at Oe.<anonymous> (https://lib/WASubContext.js:2:2386798)
at Oe.onLaunch (https://app.js:14:10)
at Oe.<anonymous> (https://lib/WASubContext.js:2:2387256)
at new Oe (https://lib/WASubContext.js:2:2388013)
at Function.<anonymous> (https://lib/WASubContext.js:2:2388325)
at https://lib/WASubContext.js:2:2374880
at https://app.js:11:1
at require (https://lib/WASubContext.js:2:2429539)
at https://usr/app-service.js:5377:10
/**
* iOS
* 客户端版本号
* 8.0.4 53.85%
* 8.0.2 30.77%
* 8.0.3 15.38%
* 基础库版本2.16.0 100%
**/
undefined is not an object (evaluating \'e.onCheckForUpdate\')
checkAppUpdate@https://app.js:35:5
https://lib/WASubContext.js:2:2386803
onLaunch@https://app.js:14:10
https://lib/WASubContext.js:2:2387261
Oe@https://lib/WASubContext.js:2:2388021
https://lib/WASubContext.js:2:2388331
https://lib/WASubContext.js:2:2374885
https://app.js:11:1
require@https://lib/WASubContext.js:2:2429540
global code@https://usr/app-service.js:5364:17
value@https://lib/WAServiceMainContext.js:2:154041
https://lib/WAServiceMainContext.js:2:157113
https://lib/WAServiceMainContext.js:2:157080
w@https://lib/WAServiceMainContext.js:2:82070
s@https://lib/WAServiceMainContext.js:2:82344
a@https://lib/WAServiceMainContext.js:2:156029
https://lib/WAServiceMainContext.js:2:157540
https://lib/WAServiceMainContext.js:2:146632
https://lib/WAServiceMainContext.js:2:259690
https://lib/WAServiceMainContext.js:2:258655
https://lib/WAServiceMainContext.js:2:258619
https://lib/WAServiceMainContext.js:2:259690
w@https://lib/WAServiceMainContext.js:2:78332
现在只能先使用定时器延迟执行此段代码,看看是否能够去除小程序后台错误日志
这个错误日志触发率在所有用户中加起来超过70%,需要重视!