小程序wx.getSystemInfo
wx.getSystemInfo(Object object)
獲取系統信息。由于歷史原因,wx.getSystemInfo 是異步的調用格式,但是是同步返回,需要異步獲取系統信息請使用 wx.getSystemInfoAsync。
以 Promise 風格 調用:支持
小程序插件:支持,需要小程序基礎庫版本不低于 1.9.6
微信 Windows 版:支持
微信 Mac 版:支持
參數
Object object
屬性 類型 默認值 必填 說明
success function 否 接口調用成功的回調函數
fail function 否 接口調用失敗的回調函數
complete function 否 接口調用結束的回調函數(調用成功、失敗都會執行)
object.success 回調函數
參數
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 客戶端平臺
合法值 說明
ios iOS微信(包含 iPhone、iPad)
android Android微信
windows Windows微信
mac macOS微信
fontSizeSetting number 用戶字體大小(單位px)。以微信客戶端「我-設置-通用-字體大小」中的設置為準 1.5.0
SDKVersion string 客戶端基礎庫版本 1.1.0
benchmarkLevel number 設備性能等級(僅 Android)。取值為:-2 或 0(該設備無法運行小游戲),-1(性能未知),>=1(設備性能值,該值越高,設備性能越好,目前最高不到50) 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 在豎屏正方向下的安全區域 2.7.0
結構屬性 類型 說明
left number 安全區域左上角橫坐標
right number 安全區域右下角橫坐標
top number 安全區域左上角縱坐標
bottom number 安全區域右下角縱坐標
width number 安全區域的寬度,單位邏輯像素
height number 安全區域的高度,單位邏輯像素
locationReducedAccuracy boolean `true` 表示模糊定位,`false` 表示精確定位,僅 iOS 支持
theme string 系統當前主題,取值為`light`或`dark`,全局配置`"darkmode":true`時才能獲取,否則為 undefined (不支持小游戲) 2.11.0
合法值 說明
dark 深色主題
light 淺色主題
host Object 當前小程序運行的宿主環境 2.12.3
結構屬性 類型 說明
appId string 宿主 app 對應的 appId
enableDebug boolean 是否已打開調試。可通過右上角菜單或 wx.setEnableDebug 打開調試。 2.15.0
deviceOrientation string 設備方向
合法值 說明
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
}
- 小程序wx.getSystemInfo
- 獲取系統信息。由于歷史原因,wx.getSystemInfo 是異步的調用格式,但是是同步返回,需要異步獲取系統信息請使用 wx.getSystemInfoAsy
- 04-02 關注:0