起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2718|回复: 3

[用户待确认] 小程序更新代码错误

[复制链接]

46

主题

168

帖子

501

积分

高级会员

Rank: 4

积分
501
QQ
发表于 2020-6-15 15:13:59 | 显示全部楼层 |阅读模式
//app.js
App({
  onLaunch: function (options) {
   this.autoUpdate()
  },
  autoUpdate : function(){
    var self = this
    if(wx.canIUse('getUpdateManager')){
      const updateManager = wx.getUpdateManager()
      // 检查小程序是否有新版本发布
      updateManager.onCheckForUpdate(function(res){
        // 请求完新版本的信息回调
        if(res.hasUpdate){
          wx.showModal({
            title: '更新提示',
            content: '检查到新版本,是否下载新版本并重启小程序?',
            success:function(res){
              if(res.confirm){
                // 下载
               self.downloadAndUpdate(updateManager)
              }else if(res.cancel){
                // 点击取消,做强制更新操作
                wx.showModal({
                  title: '温馨提示',
                  content: '必须强制更新哦,旧版本无法正常使用',
                  showCancel:false,//隐藏取消按钮
                  confirmText:'确定更新',
                  success:function(res){
                    if(res.confirm){
                      // 再次调用下载,并重启
                      self.downloadAndUpdate(updateManager)
                    }
                  }
                })

              }
            }
          })
        }
      })
    }else{
      // 增加用户体验,给出友好提示
      wx.showModal({
        title: '提示',
        content: '当前微信版本过低,无法使用该功能,请升级后重试。'
      })
    }
   
  },
  /**
   * 下载新版本并重启
   */
  downloadAndUpdate: function (updateManager) {
    var self = this
    wx.showLoading();
   
    // 监听小程序有版本更新事件,客户端主动触发
    updateManager.onUpdateReady(function(){
      wx.hideLoading();
      // 新版本下载好,调用applyUpdate
      updateManager.applyUpdate()
    })

    // 监听小程序更新失败事件
    updateManager.onUpdateFailed(function(){
      wx.showModal({
        title: '已经有新版了哦',
        content: '请你删除当前小程序,进行升级哦'
      })
    })
  }
})



大神们 这段代码 错误点在哪里 一直不成功

46

主题

168

帖子

501

积分

高级会员

Rank: 4

积分
501
QQ
 楼主| 发表于 2020-6-15 16:59:53 | 显示全部楼层
(unknown) thirdScriptError
updateManager.onCheckForUpdate is not a function;at App autoUpdate function
TypeError: updateManager.onCheckForUpdate is not a function
    at ve.autoUpdate (weapp:///app.js:24:21)
    at ve.eval (eval at n.call.document (http://127.0.0.1:16722/remote-de ... ols_ignore=true:1:1), <anonymous>:2:1931183)
    at ve.onLaunch (weapp:///app.js:17:10)
    at ve.eval (eval at n.call.document (http://127.0.0.1:16722/remote-de ... ols_ignore=true:1:1), <anonymous>:2:1931645)
    at new ve (eval at n.call.document (http://127.0.0.1:16722/remote-de ... ols_ignore=true:1:1), <anonymous>:2:1932401)
    at Function.eval (eval at n.call.document (http://127.0.0.1:16722/remote-de ... ols_ignore=true:1:1), <anonymous>:2:1932713)
    at eval (eval at n.call.document (http://127.0.0.1:16722/remote-de ... ols_ignore=true:1:1), <anonymous>:2:1919155)
    at eval (weapp:///app.js:15:1)
    at require (eval at n.call.document (http://127.0.0.1:16722/remote-de ... ols_ignore=true:1:1), <anonymous>:2:1971507)
    at eval (weapp:///app.js:87:2)
errorReport
回复 支持 反对

使用道具 举报

46

主题

168

帖子

501

积分

高级会员

Rank: 4

积分
501
QQ
 楼主| 发表于 2020-6-15 17:00:51 | 显示全部楼层
eate property 'success' on string 'getUpdateManager'
    at eval (initenv.js? [sm]:174)
    at new E (eval at n.call.document (runtime.js?devtools_ignore=true:1), <anonymous>:2:67063)
    at Object._wx2.default.<computed> [as canIUse] (initenv.js? [sm]:173)
    at ve.autoUpdate (app.js? [sm]:12)
    at ve.eval (eval at n.call.document (runtime.js?devtools_ignore=true:1), <anonymous>:2:1931183)
    at ve.onLaunch (app.js? [sm]:8)
    at ve.eval (eval at n.call.document (runtime.js?devtools_ignore=true:1), <anonymous>:2:1931645)
    at new ve (eval at n.call.document (runtime.js?devtools_ignore=true:1), <anonymous>:2:1932401)
    at Function.eval (eval at n.call.document (runtime.js?devtools_ignore=true:1), <anonymous>:2:1932713)
    at eval (eval at n.call.document (runtime.js?devtools_ignore=true:1), <anonymous>:2:1919155)
(anonymous) @ VM22:2
e.exports @ VM22:2
(anonymous) @ VM22:2
e.exports @ VM22:2
y.<computed> @ VM22:2
r @ VM22:2
(anonymous) @ VM22:2
(anonymous) @ VM22:2
(anonymous) @ VM22:2
setTimeout (async)
setTimeout @ VM22:2
_.now.f.addEventListener.f.importScripts.i @ VM22:2
h @ VM22:2
M @ VM22:2
(anonymous) @ VM22:2
e @ VM22:2
e.exports @ VM22:2
y.<computed> @ VM22:2
r @ VM22:2
(anonymous) @ VM22:2
回复 支持 反对

使用道具 举报

10

主题

2831

帖子

3783

积分

版主

Rank: 7Rank: 7Rank: 7

积分
3783
QQ
发表于 2020-6-28 11:02:53 | 显示全部楼层
设置断点进行调试运行检查。
需要发应用及正式服务器请在服务群里联系QQ:516367879。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2024-4-19 13:10 , Processed in 0.062430 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表