Skip to content

mpx.getSystemInfo(Object object)

获取系统信息。

支持情况: 微信、支付宝、web、RN

参考文档

参数

Object object

属性 类型 默认值 必填 说明

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

object.success 回调函数

参数

Object res

属性类型说明最低版本支付宝RNweb
brandstring设备品牌1.5.0
modelstring设备型号。新机型刚推出一段时间会显示unknown,微信会尽快进行适配。
pixelRationumber设备像素比
screenWidthnumber屏幕宽度,单位px1.1.0
screenHeightnumber屏幕高度,单位px1.1.0
windowWidthnumber可使用窗口宽度,单位px
windowHeightnumber可使用窗口高度,单位px
statusBarHeightnumber状态栏的高度,单位px1.9.0
languagestring微信设置的语言
versionstring微信版本号
systemstring操作系统及版本
platformstring客户端平台
合法值说明支付宝RNweb
iosiOS微信(包含 iPhone、iPad)
androidAndroid微信
ohosHarmonyOS微信
windowsWindows微信
macmacOS微信
devtools微信开发者工具
fontSizeSettingnumber用户字体大小(单位px)。以微信客户端「我-设置-通用-字体大小」中的设置为准1.5.0
SDKVersionstring客户端基础库版本1.1.0
benchmarkLevelnumber设备性能等级(仅 Android)。取值为:-2 或 0(该设备无法运行小游戏),-1(性能未知),>=1(设备性能值,该值越高,设备性能越好)
注意:性能等级当前仅反馈真机机型,暂不支持 IDE 模拟器机型
1.8.0
albumAuthorizedboolean允许微信使用相册的开关(仅 iOS 有效)2.6.0
cameraAuthorizedboolean允许微信使用摄像头的开关2.6.0
locationAuthorizedboolean允许微信使用定位的开关2.6.0
microphoneAuthorizedboolean允许微信使用麦克风的开关2.6.0
notificationAuthorizedboolean允许微信通知的开关2.6.0
notificationAlertAuthorizedboolean允许微信通知带有提醒的开关(仅 iOS 有效)2.6.0
notificationBadgeAuthorizedboolean允许微信通知带有标记的开关(仅 iOS 有效)2.6.0
notificationSoundAuthorizedboolean允许微信通知带有声音的开关(仅 iOS 有效)2.6.0
phoneCalendarAuthorizedboolean允许微信使用日历的开关2.19.3
bluetoothEnabledboolean蓝牙的系统开关2.6.0
locationEnabledboolean地理位置的系统开关2.6.0
wifiEnabledbooleanWi-Fi 的系统开关2.6.0
safeAreaObject在竖屏正方向下的安全区域。部分机型没有安全区域概念,也不会返回 safeArea 字段,开发者需自行兼容。2.7.0
safeArea 结构属性:
属性类型说明
leftnumber安全区域左上角横坐标
rightnumber安全区域右下角横坐标
topnumber安全区域左上角纵坐标
bottomnumber安全区域右下角纵坐标
widthnumber安全区域的宽度,单位逻辑像素
heightnumber安全区域的高度,单位逻辑像素
locationReducedAccuracyboolean`true` 表示模糊定位,`false` 表示精确定位,仅 iOS 支持
themestring系统当前主题,取值为light(浅色主题)或dark(深色主题),全局配置"darkmode":true时才能获取,否则为 undefined (不支持小游戏)2.11.0
hostObject当前小程序运行的宿主环境2.12.3
host 结构属性:
属性类型说明
appIdstring宿主 app 对应的 appId
enableDebugboolean是否已打开调试。可通过右上角菜单或 wx.setEnableDebug 打开调试。
deviceOrientationstring设备方向(注意:IOS客户端横屏游戏获取deviceOrientation可能不准,建议以屏幕宽高为准)值: portrait(竖屏)/landscape(横屏)

示例代码

js
mpx.getSystemInfo({
  success (res) {
    console.log(res.model)
    console.log(res.pixelRatio)
    console.log(res.windowWidth)
    console.log(res.windowHeight)
    console.log(res.language)
    console.log(res.version)
    console.log(res.platform)
  }
})