跳到主要内容
版本:3.x

Taro.getSystemInfoSync()

Taro.getSystemInfo 的同步版本

支持情况:

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

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

参考文档

类型

() => Result

参数

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地理位置的系统开关
wifiEnabledbooleanWi-Fi 的系统开关
safeAreaTaroGeneral.SafeAreaResult在竖屏正方向下的安全区域
locationReducedAccuracybooleantrue 表示模糊定位,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横屏

示例代码

try {
const res = Taro.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
}