收藏
回答

小程序更新版本后,写了更新版本的代码,但是不起作用,没有弹框

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug wx.getUpdateManager() 微信iOS客户端 7.0.5 2.8.3

/*更新版本*/

autoUpdate() {

let that = this

// 获取小程序更新机制兼容

if (wx.canIUse('getUpdateManager')) {

const updateManager = wx.getUpdateManager()

//检查小程序是否有新版本发布

updateManager.onCheckForUpdate(async(res) => {

// 请求完新版本信息的回调

if (res.hasUpdate) {

//检测到新版本,需要更新,给出提示

wx.showModal({

title: '更新提示'

content: '检测到新版本,是否重启小程序?'

showCancel: false

confirmColor: "#f6d201"

success: function(res) {

if (res.confirm) {

//用户确定下载更新小程序,小程序下载及更新静默进行

that.downloadUpdate(updateManager)

}

}

})

}

})

}

},

/*下载小程序新版本并重新启用*/

downloadUpdate(data) {

let that = this

wx.showLoading()

//静默下载更新小程序新版本

data.onUpdateReady((res) => {

wx.hideLoading()

//新的版本已经下载好,调用 applyUpdate 应用新版本并重启

data.applyUpdate()

})

data.onUpdateFailed(() => {

            wx.hideLoading()

// 新的版本下载失败

hshowModal("已经有新版本了哟", "已经有新版本了,请您删除当前小程序,重新搜索打开"

})

}

真机上没有出现这个弹框

回答关注问题邀请回答
收藏

2 个回答

  • Actor~F
    Actor~F
    2019-12-24

    autoUpdate: function() {

    var self = this

    // 获取小程序更新机制兼容

    if (wx.canIUse('getUpdateManager')) {

    const updateManager = wx.getUpdateManager()

    //1. 检查小程序是否有新版本发布

    updateManager.onCheckForUpdate(function(res) {

    // 请求完新版本信息的回调

    if (res.hasUpdate) {

    //2. 小程序有新版本,则静默下载新版本,做好更新准备

    updateManager.onUpdateReady(function() {

    updateManager.applyUpdate()

    })

    updateManager.onUpdateFailed(function() {

    // 新的版本下载失败

    wx.showModal({

    title: '已经有新版本了哟~'

    content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'

    })

    })

    }

    })

    } else {

    // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示

    wx.showModal({

    title: '提示'

    content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'

    })

    }

    },


    2019-12-24
    有用
    回复
  • 睡前原谅一切
    睡前原谅一切
    2019-12-24

    我真机出现过。。。

    2019-12-24
    有用
    回复 11
    查看更多(6)
登录 后发表内容
问题标签