当前位置:网站首页>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
边栏推荐
- dotnet-exec 0.4.0 released
- 30岁了开始自学编程,家里比较困难还来得及吗?
- great! Auto like, I use pyautogui!
- [untitled]
- 第九章 APP项目测试(2) 测试工具
- Why does the SQL statement hit the index faster than it does not?
- 初识 Flutter 的绘图组件 — CustomPaint
- Bingbing's learning notes: implementation of circular queue
- Cascading deletion of gbase 8s
- Kotlin compose perfect todo project surface rendering background and shadow
猜你喜欢

"Daily practice, happy water" 1108 IP address invalidation

Méthode de récupération des données d'ouverture du disque dur à l'état solide

Xiaobai learns MySQL - Statistical 'opportunism'

Why does the SQL statement hit the index faster than it does not?

JS, BOM, DOM (VI)

In Net 6 using dotnet format formatting code

Kotlin compose perfect todo project surface rendering background and shadow

Simple text analysis of malicious samples - Introduction

Machine learning deep learning -- Vectorization

电脑的dwg文件怎么打开
随机推荐
Kotlin Compose 完善toDo项目 Surface 渲染背景 与阴影
The SQL response is slow. What are your troubleshooting ideas?
JS call() and apply()
SOC验证环境的启动方式
Use of deferred environment variable in gbase 8s
本轮压力测试下,DeFi协议们表现如何?
Gbase 8s memory management
ROS2/DDS/QoS/主题的记录
在 .NET 6 中使用 dotnet format 格式化代码
OLAP analysis engine kylin4.0
Leader: who can use redis expired monitoring to close orders and get out of here!
Immutable learning road -- farewell to traditional copy
Huawei Hongmeng development lesson 4
Data view for gbase 8s
Cascading deletion of gbase 8s
Immutable学习之路----告别传统拷贝
Write shell script error summary
Simple text analysis of malicious samples - Introduction
The solution of wechat applet switchtab unable to take parameters
我的IC之旅——资深芯片设计验证工程师成长——“胡”说IC工程师完美进阶