Skip to main content
Version: 3.x

Taro.getSystemInfoAsync(res)

异步获取系统信息。需要一定的微信客户端版本支持,在不支持的客户端上,会使用同步实现来返回。

支持情况:

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

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

参考文档

类型​

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

参数​

参数类型
resOption

Option​

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

Result​

参数类型必填说明
brandstring是设备品牌
modelstring是设备型号
pixelRationumber是设备像素比
screenWidthnumber是屏幕宽度,单位px
screenHeightnumber是屏幕高度,单位px
windowWidthnumber是可使用窗口宽度,单位px
windowHeightnumber是可使用窗口高度,单位px
statusBarHeightnumber否状态栏的高度,单位px
languagestring是微信设置的语言
versionstring否微信版本号
systemstring是操作系统及版本
platformstring是客户端平台
fontSizeSettingnumber否用户字体大小(单位px)。以微信客户端「我-设置-通用-字体大小」中的设置为准
SDKVersionstring否客户端基础库版本
benchmarkLevelnumber是设备性能等级(仅Android小游戏)。取值为:-2 或 0(该设备无法运行小游戏),-1(性能未知),>=1(设备性能值,该值越高,设备性能越好,目前最高不到50)
albumAuthorizedboolean否允许微信使用相册的开关(仅 iOS 有效)
cameraAuthorizedboolean否允许微信使用摄像头的开关
locationAuthorizedboolean否允许微信使用定位的开关
microphoneAuthorizedboolean否允许微信使用麦克风的开关
notificationAuthorizedboolean否允许微信通知的开关
notificationAlertAuthorizedboolean否允许微信通知带有提醒的开关(仅 iOS 有效)
notificationBadgeAuthorizedboolean否允许微信通知带有标记的开关(仅 iOS 有效)
notificationSoundAuthorizedboolean否允许微信通知带有声音的开关(仅 iOS 有效)
phoneCalendarAuthorizedboolean否允许微信使用日历的开关
bluetoothEnabledboolean否蓝牙的系统开关
locationEnabledboolean否地理位置的系统开关
wifiEnabledboolean否Wi-Fi 的系统开关
safeAreaTaroGeneral.SafeAreaResult否在竖屏正方向下的安全区域
locationReducedAccuracyboolean否true 表示模糊定位,false 表示精确定位,仅 iOS 支持
themekeyof Theme否系统当前主题,取值为light或dark,全局配置"darkmode":true时才能获取,否则为 undefined (不支持小游戏)
hostHost否当前小程序运行的宿主环境
enableDebugboolean否是否已打开调试。可通过右上角菜单或 Taro.setEnableDebug 打开调试。
deviceOrientationkeyof DeviceOrientation否设备方向
environmentstring否小程序当前运行环境

Theme​

系统主题合法值

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

Host​

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

DeviceOrientation​

设备方向合法值

参数说明
portrait竖屏
landscape横屏

示例代码​

Taro.getSystemInfoAsync({
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)
}
})