Taro.getSystemInfo(res)

获取系统信息,支持 Promise 化使用。

支持情况:getSystemInfo - 图1 getSystemInfo - 图2 getSystemInfo - 图3

微信小程序: 小程序可以在微信和企业微信中调用此接口,但是在企业微信中调用此接口时,会额外返回一个 environment 字段(微信中不返回),如此字段值为 wxwork,则表示当前小程序运行在企业微信环境中。

H5: 不支持 version、statusBarHeight、fontSizeSetting、SDKVersion

参考文档

类型

  1. (res?: Option) => Promise<Result>

参数

参数 类型
res Option

Option

参数 类型 必填 说明
success (res: Result) => void 接口调用成功的回调函数
fail (res: TaroGeneral.CallbackResult) => void 接口调用失败的回调函数
complete (res: any) => void 接口调用结束的回调函数(调用成功、失败都会执行)

Result

参数 类型 必填 说明
brand string 设备品牌
model string 设备型号
pixelRatio number 设备像素比
screenWidth number 屏幕宽度,单位px
screenHeight number 屏幕高度,单位px
windowWidth number 可使用窗口宽度,单位px
windowHeight number 可使用窗口高度,单位px
statusBarHeight number 状态栏的高度,单位px
language string 微信设置的语言
version string 微信版本号
system string 操作系统及版本
platform string 客户端平台
fontSizeSetting number 用户字体大小(单位px)。以微信客户端「我-设置-通用-字体大小」中的设置为准
SDKVersion string 客户端基础库版本
benchmarkLevel number 设备性能等级(仅Android小游戏)。取值为:-2 或 0(该设备无法运行小游戏),-1(性能未知),>=1(设备性能值,该值越高,设备性能越好,目前最高不到50)
albumAuthorized boolean 允许微信使用相册的开关(仅 iOS 有效)
cameraAuthorized boolean 允许微信使用摄像头的开关
locationAuthorized boolean 允许微信使用定位的开关
microphoneAuthorized boolean 允许微信使用麦克风的开关
notificationAuthorized boolean 允许微信通知的开关
notificationAlertAuthorized boolean 允许微信通知带有提醒的开关(仅 iOS 有效)
notificationBadgeAuthorized boolean 允许微信通知带有标记的开关(仅 iOS 有效)
notificationSoundAuthorized boolean 允许微信通知带有声音的开关(仅 iOS 有效)
phoneCalendarAuthorized boolean 允许微信使用日历的开关
bluetoothEnabled boolean 蓝牙的系统开关
locationEnabled boolean 地理位置的系统开关
wifiEnabled boolean Wi-Fi 的系统开关
safeArea TaroGeneral.SafeAreaResult 在竖屏正方向下的安全区域
locationReducedAccuracy boolean true 表示模糊定位,false 表示精确定位,仅 iOS 支持
theme keyof Theme 系统当前主题,取值为light或dark,全局配置”darkmode”:true时才能获取,否则为 undefined (不支持小游戏)
host Host 当前小程序运行的宿主环境
enableDebug boolean 是否已打开调试。可通过右上角菜单或 Taro.setEnableDebug 打开调试。
deviceOrientation keyof DeviceOrientation 设备方向
environment string 小程序当前运行环境

Theme

系统主题合法值

参数 说明
dark 深色主题
light 浅色主题

Host

参数 类型 说明
appId string 宿主 app 对应的 appId

DeviceOrientation

设备方向合法值

参数 说明
portrait 竖屏
landscape 横屏

示例代码

示例 1

  1. Taro.getSystemInfo({
  2. success: res => console.log(res)
  3. })
  4. .then(res => console.log(res))

示例 2

  1. Taro.getSystemInfo({
  2. success: function (res) {
  3. console.log(res.model)
  4. console.log(res.pixelRatio)
  5. console.log(res.windowWidth)
  6. console.log(res.windowHeight)
  7. console.log(res.language)
  8. console.log(res.version)
  9. console.log(res.platform)
  10. }
  11. })