PluginUpdateManager.onCheckForUpdate 监听函数

微信小程序插件:不支持

功能描述

监听向微信后台请求检查插件更新结果事件。微信在微信小程序每次启动(包括热启动)时自动检查插件更新,不需由开发者主动触发。

参数

function listener

向微信后台请求检查插件更新结果事件的监听函数

参数

Object res
属性 类型 说明
hasUpdate boolean 是否有插件新版本
pluginVersion string 插件新版本号。仅当 hasUpdate 为 true 时返回

PluginUpdateManager

基础库 2.25.0 开始支持,低版本需做兼容处理。

PluginUpdateManager 对象,用来管理插件更新,可通过 wx.getPluginUpdateManager 接口获取实例。

方法

PluginUpdateManager.onCheckForUpdate(function listener)

监听向微信后台请求检查插件更新结果事件。微信在微信小程序每次启动(包括热启动)时自动检查插件更新,不需由开发者主动触发。

PluginUpdateManager.onUpdateReady(function listener)

监听插件有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调

PluginUpdateManager.onUpdateFailed(function listener)

监听插件更新失败事件。插件有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)后回调

示例代码

const pluginUpdateManager = wx.getPluginUpdateManager({
  pluginId: 'wx1234567890abcdef'
})

pluginUpdateManager.onCheckForUpdate(function (res) {
  // 请求完插件新版本信息的回调
  console.log(res.hasUpdate)
  if (res.hasUpdate) {
    console.log(res.pluginVersion)
  }
})

pluginUpdateManager.onUpdateReady(function (res) {
  wx.showModal({
    title: '更新提示',
    content: '插件新版本已经准备好,是否重启应用?',
    success: function (modalRes) {
      if (modalRes.confirm) {
        // 插件新版本已经下载好,调用 applyUpdate 应用新版本并重启
        wx.getUpdateManager().applyUpdate()
      }
    }
  })
})

pluginUpdateManager.onUpdateFailed(function (res) {
  // 插件新版本下载失败
  console.log(res.pluginVersion)
})

UpdateManager

基础库 1.9.90 开始支持,低版本需做兼容处理。

微信小程序插件:不支持

微信 Windows 版:支持

微信 鸿蒙 OS 版:支持

功能描述

获取全局唯一的版本更新管理器,用于管理微信小程序更新。关于微信小程序的更新机制,可以查看运行机制文档。

返回值

UpdateManager

更新管理器对象

示例代码

示例代码

wx.updateWeChatApp(Object object)

基础库 2.12.0 开始支持,低版本需做兼容处理。

以 Promise 风格 调用:支持

微信小程序插件:支持,需要微信小程序基础库版本不低于 2.12.0

微信 Mac 版:支持

微信 鸿蒙 OS 版:支持

功能描述

更新客户端版本。当判断用户微信小程序所在客户端版本过低时,可使用该接口跳转到更新微信页面。

参数

Object object

属性 类型 默认值 必填 说明
success function 否 接口调用成功的回调函数
fail function 否 接口调用失败的回调函数
complete function 否 接口调用结束的回调函数(调用成功、失败都会执行)

微信小程序 wx.getAppAuthorizeSetting()

基础库 2.20.1 开始支持,低版本需做兼容处理。

微信小程序插件:支持,需要微信小程序基础库版本不低于 2.21.3

微信 Windows 版:支持

微信 Mac 版:支持

微信 鸿蒙 OS 版:支持

功能描述

获取微信APP授权设置

返回值

Object

属性 类型 说明
albumAuthorized ‘authorized’/’denied’/’not determined’ 允许微信使用相册的开关(仅 iOS 有效)
bluetoothAuthorized ‘authorized’/’denied’/’not determined’ 允许微信使用蓝牙的开关(安卓基础库 3.5.0 以上有效)
cameraAuthorized ‘authorized’/’denied’/’not determined’ 允许微信使用摄像头的开关
locationAuthorized ‘authorized’/’denied’/’not determined’ 允许微信使用定位的开关
locationReducedAccuracy boolean 定位准确度。true 表示模糊定位,false 表示精确定位(仅 iOS 有效)
microphoneAuthorized ‘authorized’/’denied’/’not determined’ 允许微信使用麦克风的开关
notificationAuthorized ‘authorized’/’denied’/’not determined’ 允许微信通知的开关
notificationAlertAuthorized ‘authorized’/’denied’/’not determined’ 允许微信通知带有提醒的开关(仅 iOS 有效)
notificationBadgeAuthorized ‘authorized’/’denied’/’not determined’ 允许微信通知带有标记的开关(仅 iOS 有效)
notificationSoundAuthorized ‘authorized’/’denied’/’not determined’ 允许微信通知带有声音的开关(仅 iOS 有效)
phoneCalendarAuthorized ‘authorized’/’denied’/’not determined’ 允许微信读写日历的开关

示例代码

const appAuthorizeSetting = wx.getAppAuthorizeSetting()

console.log(appAuthorizeSetting.albumAuthorized)
console.log(appAuthorizeSetting.bluetoothAuthorized)
console.log(appAuthorizeSetting.cameraAuthorized)
console.log(appAuthorizeSetting.locationAuthorized)
console.log(appAuthorizeSetting.locationReducedAccuracy)
console.log(appAuthorizeSetting.microphoneAuthorized)
console.log(appAuthorizeSetting.notificationAlertAuthorized)
console.log(appAuthorizeSetting.notificationAuthorized)
console.log(appAuthorizeSetting.notificationBadgeAuthorized)
console.log(appAuthorizeSetting.notificationSoundAuthorized)
console.log(appAuthorizeSetting.phoneCalendarAuthorized)

返回值说明

'authorized' 表示已经获得授权,无需再次请求授权;'denied' 表示请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限)'non determined' 表示尚未请求授权,会在微信下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关)

微信小程序 wx.getAppBaseInfo()

基础库 2.20.1 开始支持,低版本需做兼容处理。

微信小程序插件:支持,需要微信小程序基础库版本不低于 2.21.3

微信 Windows 版:支持

微信 Mac 版:支持

微信 鸿蒙 OS 版:支持

功能描述

获取微信APP基础信息

返回值

Object

属性 类型 说明 最低版本
SDKVersion string 客户端基础库版本
enableDebug boolean 是否已打开调试。可通过右上角菜单或 wx.setEnableDebug 打开调试。
host Object 当前微信小程序运行的宿主环境
结构属性 类型 说明
appId string 宿主 app(第三方App) 对应的 appId (当微信小程序运行在第三方App环境时才返回)
language string 微信设置的语言
version string 微信版本号
PCKernelVersion string PC 内核版本号,仅在 PC 端存在该值
theme string 系统当前主题,取值为`light`或`dark`,全局配置`”darkmode”:true`时才能获取,否则为 undefined (不支持小游戏)
合法值 说明
dark 深色主题
light 浅色主题
fontSizeScaleFactor number 微信字体大小缩放比例
fontSizeSetting number 微信字体大小,单位px 2.23.4

示例代码

const appBaseInfo = wx.getAppBaseInfo()

console.log(appBaseInfo.SDKVersion)
console.log(appBaseInfo.enableDebug)
console.log(appBaseInfo.host)
console.log(appBaseInfo.language)
console.log(appBaseInfo.version)
console.log(appBaseInfo.theme)

wx.getDeviceBenchmarkInfo(Object object)

基础库 3.4.5 开始支持,低版本需做兼容处理。

以 Promise 风格 调用:不支持

微信小程序插件:不支持

微信 鸿蒙 OS 版:支持

功能描述

获取设备性能得分和机型档位数据

参数

Object object

属性 类型 默认值 必填 说明
success function 否 接口调用成功的回调函数
fail function 否 接口调用失败的回调函数
complete function 否 接口调用结束的回调函数(调用成功、失败都会执行)

object.success 回调函数

参数
Object res
属性 类型 说明 最低版本
benchmarkLevel number 设备性能等级。-1(性能未知),>=1(设备性能值,该值越高,设备性能越好)
注意:
1. 设备的benchmarkLevel值不会随着时间的推移而变化,移动端设备目前最高不超过50
3.4.5
modelLevel number 设备机型档位。0(档位未知),1(高档机),2(中档机),3(低档机)
注意:设备的机型档位会随着时间的推移而变化,因此在使用时请谨慎对待;若业务逻辑依赖于机型档位,但担心受到机型档位变化的影响,请参考设备档位映射文档自行判断机型档位
3.4.5

示例代码

wx.getDeviceBenchmarkInfo({
  success (res) {
    console.log(res.benchmarkLevel)
    console.log(res.modelLevel)
  }
})

wx.getDeviceInfo()

基础库 2.20.1 开始支持,低版本需做兼容处理。

微信小程序插件:支持,需要微信小程序基础库版本不低于 2.21.3

微信 Windows 版:支持

微信 Mac 版:支持

微信 鸿蒙 OS 版:支持

功能描述

获取设备基础信息

返回值

Object

属性 类型 说明 最低版本
abi string 应用(微信APP)二进制接口类型(仅 Android 支持)
deviceAbi string 设备二进制接口类型(仅 Android 支持) 2.25.1
benchmarkLevel number 设备性能等级(仅 Android 支持)。取值为:-2 或 0(该设备无法运行小游戏),-1(性能未知),>=1(设备性能值,该值越高,设备性能越好,目前最高不到50)
注意:从基础库3.4.5开始,本返回值停止维护,请使用wx.getDeviceBenchmarkInfo获取设备性能等级
brand string 设备品牌
model string 设备型号。新机型刚推出一段时间会显示unknown,微信会尽快进行适配。
system string 操作系统及版本
platform string 客户端平台
合法值 说明
ios iOS微信(包含 iPhone、iPad)
android Android微信
ohos HarmonyOS 手机端微信
ohos_pc HarmonyOS PC微信
windows Windows微信
mac macOS微信
devtools 微信开发者工具
cpuType string 设备 CPU 型号(仅 Android 支持)(提示:GPU 型号可通过 WebGLRenderingContext.getExtension(‘WEBGL_debug_renderer_info’) 来获取) 2.29.0
memorySize string 设备内存大小,单位为 MB 2.30.0

示例代码

const deviceInfo = wx.getDeviceInfo()

console.log(deviceInfo.abi)
console.log(deviceInfo.benchmarkLevel)
console.log(deviceInfo.brand)
console.log(deviceInfo.model)
console.log(deviceInfo.platform)
console.log(deviceInfo.system)