当前位置:网站首页>Wechat applet new version prompt update
Wechat applet new version prompt update
2022-06-25 04:48:00 【Oglie's magic slippers~】
Wechat applet new version prompt update
The company's small program project goes online , There will be small version iterations later . In order to enable users to use the functions of the latest version in time after our version iteration . Do the following optimization …
Knowledge point 1: When the user clicks the upper left corner to close , Or press the device Home Key to leave wechat , The applet was not destroyed directly , It's backstage ;
When you enter wechat again or open the applet again , It will enter the front desk from the backstage , Only when the applet enters the background for a certain time , Or the system resources are too high , Will be really destroyed .
Knowledge point 2: The startup of small programs is divided into " Cold start " and “ Hot start ”.
Hot start means : After the applet opens , Over a period of time ( at present :5 minute ) Opened again , The applet in the background will be switched to the foreground .
Cold start means : After the applet is first opened or destroyed, it is opened again
Knowledge point 3: An updated version
Cold start , If a new version is found , The new version of the code package will be downloaded asynchronously , At the same time, it starts with the local package of the client , That is, the new version of the applet will not be applied until the next cold start .
If you want to apply the latest version right away , Use wx.getUpdateManager API To deal with .
The code is as follows :
// stay app.js Write the following code in
onLaunch () {
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
console.log('onCheckForUpdate====', res)
// Call back after requesting new version information
if (res.hasUpdate) {
console.log('res.hasUpdate====')
updateManager.onUpdateReady(function () {
wx.showModal({
title: ' Update hints ',
content: ' The new version is ready , Restart application or not ?',
success: function (res) {
console.log('success====', res)
// res: {errMsg: "showModal: ok", cancel: false, confirm: true}
if (res.confirm) {
// The new version has been downloaded , call applyUpdate Apply new version and restart
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
// New version download failed
wx.showModal({
title: ' There is a new version ~',
content: ' The new version is online ~, Please delete the current applet , Search again open ~'
})
})
}
})
}
}
Knowledge point 4: When the applet is reinitialized, it will trigger onLaunch event . onLaunch The event will be triggered on the page onShow Before the incident . The updated version of the applet can be written in onLaunch in .
Knowledge point 5:
The version update cannot be tested in the development and experience version
It needs to be in the developer tool , Select... At compile time " Simulation update compilation "

Click ok :
Console display :
Knowledge point 6: With the continuous updating of small programs , Some functions may require the latest version of wechat client to use . At this time, you can pop up a window to prompt the user to update to the latest version of wechat
if (wx.canIUse('getUpdateManager')) {
...
} else {
// can't use getUpdateManager
wx.showModal({
title: ' Tips ',
content: ' Current wechat version is too low , This feature is not available , Please upgrade to the latest wechat version and try again .'
})
Full version :
onLaunch () {
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
if (res.hasUpdate) {
updateManager.onUpdateReady(function () {
wx.showModal({
title: ' Update hints ',
content: ' The new version is ready , Restart application or not ?',
success: function (res) {
if (res.confirm) {
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
wx.showModal({
title: ' There is a new version ~',
content: ' The new version is online ~, Please delete the current applet , Search again open ~'
})
})
}
})
} else {
wx.showModal({
title: ' Tips ',
content: ' Current wechat version is too low , This feature is not available , Please upgrade to the latest wechat version and try again .'
})
}
}
Knowledge point 7: If in onLaunch In order to make a request , This is an asynchronous request . If there are requirements for interaction sequence , Such as : Version update – Retrieve data -- User presentation , Then it needs to be considered in callback To retrieve the data in .
Knowledge point 8:
When the applet starts , Normally, it will be hot updated , Download the new version of the package , The next boot will use the new package . However, it is found that the update is unsuccessful .
The official answer is : The effectiveness of the policy is related to the network environment, release time and other factors , Will let the applet update as quickly as possible , But there is no guarantee that every hot update will succeed .
Knowledge point 9:
Asynchronous updates of applets occur during cold start . Hot updates are not officially recommended . reason :

Official documents – to update
Reprinted from : Simple books
The original author : Little devil Fairy
link :https://www.jianshu.com/p/4f5e3faaf483
边栏推荐
- How do the defi protocols perform under this round of stress test?
- 三角形类(构造与析构)
- JS call() and apply()
- php开发支付宝支付功能之扫码支付流程图
- 华为鸿蒙开发第四课
- LabVIEW development gas regulator
- Why is the TCP handshake just 3 times?
- Introduction to the isolation level of gbase 8s
- Kotlin Compose 完善toDo项目 Surface 渲染背景 与阴影
- 融合CDN,为客户打造极致服务体验!
猜你喜欢

Efficient NoSQL database service Amazon dynamodb experience sharing

Upgrade PHP to php7 The impact of X (I). The problem of session retention. Keep login

《QDebug 2022年6月》

魔法猪系统重装大师怎么使用

我的IC之旅——资深芯片设计验证工程师成长——“胡”说IC工程师完美进阶
Triangle class (construction and deconstruction)

Web3 DAPP user experience best practices

Cnpm: unable to load file c:\users\administrator\appdata\roaming\npm\cnpm PS1 because running scripts is prohibited on this system.

js中的concat()

js的arguments
随机推荐
Part I Verilog quick start
Concat() in JS
Successfully solved: selenium common. exceptions. TimeoutException: Message: timeout: Timed out receiving message from
Cookie & session & JSP (XII)
《牛客刷verilog》Part I Verilog快速入门
Package for gbase 8s
CTF_ Web: Changan cup-2021 old but a little new & asuka
great! Auto like, I use pyautogui!
Unity Quad culls shaders with back faces and transparent parts
Opensea PHP development kit
三角形类(构造与析构)
Google Earth Engine(GEE)——全球JRC/GSW1_1/YearlyHistory数据集的批量下载(中国区域)
MySQL concept and operation (III)
Immutable學習之路----告別傳統拷貝
Chapter IX app project test (2) test tools
[Flink] problems and solutions of the continuous growth of checkpoint size in rocksdb incremental mode
以太网是什么要怎么连接电脑
成功解决:selenium.common.exceptions.TimeoutException: Message: timeout: Timed out receiving message from
js的arguments
Introduction to the isolation level of gbase 8s