小程序wx.getSystemInfo
wx.getSystemInfo(Object object)
獲取系統(tǒng)信息。由于歷史原因,wx.getSystemInfo 是異步的調(diào)用格式,但是是同步返回,需要異步獲取系統(tǒng)信息請使用 wx.getSystemInfoAsync。
以 Promise 風(fēng)格 調(diào)用:支持
小程序插件:支持,需要小程序基礎(chǔ)庫版本不低于 1.9.6
微信 Windows 版:支持
微信 Mac 版:支持
參數(shù)
Object object
屬性 類型 默認(rèn)值 必填 說明
success function 否 接口調(diào)用成功的回調(diào)函數(shù)
fail function 否 接口調(diào)用失敗的回調(diào)函數(shù)
complete function 否 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)
object.success 回調(diào)函數(shù)
參數(shù)
Object res
屬性 類型 說明 最低版本
brand string 設(shè)備品牌 1.5.0
model string 設(shè)備型號。新機(jī)型剛推出一段時間會顯示unknown,微信會盡快進(jìn)行適配。
pixelRatio number 設(shè)備像素比
screenWidth number 屏幕寬度,單位px 1.1.0
screenHeight number 屏幕高度,單位px 1.1.0
windowWidth number 可使用窗口寬度,單位px
windowHeight number 可使用窗口高度,單位px
statusBarHeight number 狀態(tài)欄的高度,單位px 1.9.0
language string 微信設(shè)置的語言
version string 微信版本號
system string 操作系統(tǒng)及版本
platform string 客戶端平臺
合法值 說明
ios iOS微信(包含 iPhone、iPad)
android Android微信
windows Windows微信
mac macOS微信
fontSizeSetting number 用戶字體大。▎挝籶x)。以微信客戶端「我-設(shè)置-通用-字體大小」中的設(shè)置為準(zhǔn) 1.5.0
SDKVersion string 客戶端基礎(chǔ)庫版本 1.1.0
benchmarkLevel number 設(shè)備性能等級(僅 Android)。取值為:-2 或 0(該設(shè)備無法運(yùn)行小游戲),-1(性能未知),>=1(設(shè)備性能值,該值越高,設(shè)備性能越好,目前最高不到50) 1.8.0
albumAuthorized boolean 允許微信使用相冊的開關(guān)(僅 iOS 有效) 2.6.0
cameraAuthorized boolean 允許微信使用攝像頭的開關(guān) 2.6.0
locationAuthorized boolean 允許微信使用定位的開關(guān) 2.6.0
microphoneAuthorized boolean 允許微信使用麥克風(fēng)的開關(guān) 2.6.0
notificationAuthorized boolean 允許微信通知的開關(guān) 2.6.0
notificationAlertAuthorized boolean 允許微信通知帶有提醒的開關(guān)(僅 iOS 有效) 2.6.0
notificationBadgeAuthorized boolean 允許微信通知帶有標(biāo)記的開關(guān)(僅 iOS 有效) 2.6.0
notificationSoundAuthorized boolean 允許微信通知帶有聲音的開關(guān)(僅 iOS 有效) 2.6.0
phoneCalendarAuthorized boolean 允許微信使用日歷的開關(guān) 2.19.3
bluetoothEnabled boolean 藍(lán)牙的系統(tǒng)開關(guān) 2.6.0
locationEnabled boolean 地理位置的系統(tǒng)開關(guān) 2.6.0
wifiEnabled boolean Wi-Fi 的系統(tǒng)開關(guān) 2.6.0
safeArea Object 在豎屏正方向下的安全區(qū)域 2.7.0
結(jié)構(gòu)屬性 類型 說明
left number 安全區(qū)域左上角橫坐標(biāo)
right number 安全區(qū)域右下角橫坐標(biāo)
top number 安全區(qū)域左上角縱坐標(biāo)
bottom number 安全區(qū)域右下角縱坐標(biāo)
width number 安全區(qū)域的寬度,單位邏輯像素
height number 安全區(qū)域的高度,單位邏輯像素
locationReducedAccuracy boolean `true` 表示模糊定位,`false` 表示精確定位,僅 iOS 支持
theme string 系統(tǒng)當(dāng)前主題,取值為`light`或`dark`,全局配置`"darkmode":true`時才能獲取,否則為 undefined (不支持小游戲) 2.11.0
合法值 說明
dark 深色主題
light 淺色主題
host Object 當(dāng)前小程序運(yùn)行的宿主環(huán)境 2.12.3
結(jié)構(gòu)屬性 類型 說明
appId string 宿主 app 對應(yīng)的 appId
enableDebug boolean 是否已打開調(diào)試?赏ㄟ^右上角菜單或 wx.setEnableDebug 打開調(diào)試。 2.15.0
deviceOrientation string 設(shè)備方向
合法值 說明
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
}
作者:大學(xué)生新聞網(wǎng) 來源:大學(xué)生新聞網(wǎng)
- 小程序wx.getSystemInfo
- 獲取系統(tǒng)信息。由于歷史原因,wx.getSystemInfo 是異步的調(diào)用格式,但是是同步返回,需要異步獲取系統(tǒng)信息請使用 wx.getSystemInfoAsy
- 04-02 關(guān)注:0