Home > WeChat Applet > Mini Program Development > How to solve the problem of slow coverage of new versions of mini programs

How to solve the problem of slow coverage of new versions of mini programs

王林
Release: 2021-01-20 09:39:22
forward
2770 people have browsed it

How to solve the problem of slow coverage of new versions of mini programs

Problem:

Since the update mechanism of the mini program is asynchronous, some users will not use the new version immediately, which results in the new version of the mini program being overwritten. The rate is relatively slow.

(Learning video sharing: Programming video)

Cold start, hot start

小程序启动会有两种情况,一种是「冷启动」,一种是「热启动」。 
	冷启动指的是用户首次打开或小程序被微信主动销毁后再次打开的情况,此时小程序需要重新加载启动。
	假如用户已经打开过某小程序,然后在一定时间内再次打开该小程序(目前:5分钟),此时无需重新启动这个过程就是热启动;
Copy after login

Note: The basic library must be 1.9.90 or In later versions, after adding mandatory updates, it will not take effect until the next version!

Solution

1. Delete the mini program, and then search again to add the mini program, or clear WeChat cache data (the user experience is too poor)

2. Force update, code As follows:

Front-end code: Add

		  onLaunch: function () {
		    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) {
		            // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
		            updateManager.applyUpdate()
		          }
		        }
		      })
		    })
		    updateManager.onUpdateFailed(function () {
		      // 新的版本下载失败
		      wx.showModal({
		        title: '更新提示',
		        content: '新版本下载失败',
		        showCancel: false
		      })
		    })
		  }
Copy after login

test code in app.js

In WeChat developer tools, select custom compilation, select a page, and check Compilation simulation update for the next time

How to solve the problem of slow coverage of new versions of mini programs

How to solve the problem of slow coverage of new versions of mini programs

WeChat official document knowledge

从基础库 1.9.90 开始,微信提供了 wx.getUpdateManager 接口,使用该接口,可以获知是否有新版本小程序、
新版本是否下载好以及应用新版本的能力。当小程序冷启动时,如果有新版本,会马上触发新版本的下载。

wx.getUpdateManager 接口会返回一个 UpdateManager 实例,UpdateManager 包含了三个回调:
onCheckForUpdate:当小程序向后台请求完新版本信息,会通知这个版本告知检查结果
 onUpdateReady:当新版本下载完成,会回调这个事件
 onUpdateFailed: 当新版本下载失败,会回调这个事件

还有重启应用新版本的接口:
 applyUpdate:当新版本下载完成(onUpdateReady),调用该方法会强制当前小程序应用上新版本并重启
Copy after login

Official address: Mini program forced update Official address

Related recommendations: Mini Program Development Tutorial

The above is the detailed content of How to solve the problem of slow coverage of new versions of mini programs. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template