随笔 - 2649  文章 - 2452  评论 - 0  阅读 - 69979

wx.getSystemInfoSync

Object wx.getSystemInfoSync()

从基础库 2.20.1 开始,本接口停止维护,请使用 wx.getSystemSettingwx.getAppAuthorizeSettingwx.getDeviceInfowx.getWindowInfowx.getAppBaseInfo 代替

Promise 风格 调用:支持

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

微信 Windows 版:支持

微信 Mac 版:支持

微信 鸿蒙 OS 版:支持

功能描述

wx.getSystemInfo 的同步版本

返回值

Object res

属性 类型 说明 最低版本
brand string 设备品牌 1.5.0
model string 设备型号。新机型刚推出一段时间会显示unknown,微信会尽快进行适配。
pixelRatio number 设备像素比
screenWidth number 屏幕宽度,单位px 1.1.0
screenHeight number 屏幕高度,单位px 1.1.0
windowWidth number 可使用窗口宽度,单位px
windowHeight number 可使用窗口高度,单位px
statusBarHeight number 状态栏的高度,单位px 1.9.0
language string 微信设置的语言
version string 微信版本号
system string 操作系统及版本
platform string 客户端平台
合法值说明iosiOS微信(包含 iPhone、iPad)androidAndroid微信ohosHarmonyOS微信windowsWindows微信macmacOS微信devtools微信开发者工具
fontSizeSetting number 用户字体大小(单位px)。以微信客户端「我-设置-通用-字体大小」中的设置为准 1.5.0
SDKVersion string 客户端基础库版本 1.1.0
benchmarkLevel number 设备性能等级(仅 Android)。取值为:-2 或 0(该设备无法运行小游戏),-1(性能未知),>=1(设备性能值,该值越高,设备性能越好) 注意:性能等级当前仅反馈真机机型,暂不支持 IDE 模拟器机型 1.8.0
albumAuthorized boolean 允许微信使用相册的开关(仅 iOS 有效) 2.6.0
cameraAuthorized boolean 允许微信使用摄像头的开关 2.6.0
locationAuthorized boolean 允许微信使用定位的开关 2.6.0
microphoneAuthorized boolean 允许微信使用麦克风的开关 2.6.0
notificationAuthorized boolean 允许微信通知的开关 2.6.0
notificationAlertAuthorized boolean 允许微信通知带有提醒的开关(仅 iOS 有效) 2.6.0
notificationBadgeAuthorized boolean 允许微信通知带有标记的开关(仅 iOS 有效) 2.6.0
notificationSoundAuthorized boolean 允许微信通知带有声音的开关(仅 iOS 有效) 2.6.0
phoneCalendarAuthorized boolean 允许微信使用日历的开关 2.19.3
bluetoothEnabled boolean 蓝牙的系统开关 2.6.0
locationEnabled boolean 地理位置的系统开关 2.6.0
wifiEnabled boolean Wi-Fi 的系统开关 2.6.0
safeArea Object 在竖屏正方向下的安全区域。部分机型没有安全区域概念,也不会返回 safeArea 字段,开发者需自行兼容。 2.7.0
结构属性类型说明leftnumber安全区域左上角横坐标rightnumber安全区域右下角横坐标topnumber安全区域左上角纵坐标bottomnumber安全区域右下角纵坐标widthnumber安全区域的宽度,单位逻辑像素heightnumber安全区域的高度,单位逻辑像素
locationReducedAccuracy boolean true 表示模糊定位,false 表示精确定位,仅 iOS 支持
theme string 系统当前主题,取值为lightdark,全局配置"darkmode":true时才能获取,否则为 undefined (不支持小游戏) 2.11.0
合法值说明dark深色主题light浅色主题
host Object 当前小程序运行的宿主环境 2.12.3
结构属性类型说明appIdstring宿主 app 对应的 appId
enableDebug boolean 是否已打开调试。可通过右上角菜单或 wx.setEnableDebug 打开调试。 2.15.0
deviceOrientation string 设备方向(注意:IOS客户端横屏游戏获取deviceOrientation可能不准,建议以屏幕宽高为准)
合法值说明portrait竖屏landscape横屏

示例代码

在开发者工具中预览效果

wx.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)
  }
})
try {
  const res = wx.getSystemInfoSync()
  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)
} catch (e) {
  // Do something when catch error
}

注意事项

posted on   AtlasLapetos  阅读(249)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

点击右上角即可分享
微信分享提示