File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- //app.js
1+ import versionUtil from './utils/version-util'
22App ( {
33 onLaunch : function ( ) {
4-
4+ // 检查更新
5+ versionUtil . checkUpdate ( )
56 } ,
67
78 globalData : {
89
910 }
10- } ) ;
11+ } ) ;
Original file line number Diff line number Diff line change 1+ // 小程序启动时检查版本
2+ class VersionUtil {
3+ /**
4+ * 检查更新
5+ */
6+ checkUpdate ( ) {
7+ const updateManager = wx . getUpdateManager ( )
8+ updateManager . onCheckForUpdate ( ( hasUpdate ) => {
9+ if ( hasUpdate ) {
10+ updateManager . onUpdateReady ( ( ) => {
11+ wx . showModal ( {
12+ title :'更新提示' ,
13+ content :'有新版本啦!要更新看看吗' ,
14+ success ( res ) {
15+ if ( res . confirm ) {
16+ updateManager . applyUpdate ( )
17+ }
18+ }
19+ } )
20+ } )
21+
22+ updateManager . onUpdateFailed ( function ( ) {
23+ // 新版本下载失败
24+ wx . showModal ( {
25+ title : '更新提示' ,
26+ content : '有新版本啦!删除当前小程序,重新打开就能更新啦!'
27+ } )
28+ } )
29+ }
30+ } )
31+
32+
33+ }
34+ }
35+
36+ const versionUtil = new VersionUtil ( )
37+ export default versionUtil
You can’t perform that action at this time.
0 commit comments