微信小程序API-設(shè)備-系統(tǒng)信息

2022-05-11 16:51 更新

wx.getSystemInfo(OBJECT)

獲取系統(tǒng)信息。

OBJECT參數(shù)說(shuō)明:

參數(shù) 類型 必填 說(shuō)明
success Function 接口調(diào)用成功的回調(diào)
fail Function 接口調(diào)用失敗的回調(diào)函數(shù)
complete Function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行)

success回調(diào)參數(shù)說(shuō)明:

參數(shù) 說(shuō)明 最低版本
model 手機(jī)型號(hào)  
pixelRatio 設(shè)備像素比  
screenWidth 屏幕寬度 1.1.0
screenHeight 屏幕高度 1.1.0
windowWidth 可使用窗口寬度  
windowHeight 可使用窗口高度  
language 微信設(shè)置的語(yǔ)言  
version 微信版本號(hào)  
system 操作系統(tǒng)版本  
platform 客戶端平臺(tái)  
fontSizeSetting 用戶字體大小設(shè)置。以“我-設(shè)置-通用-字體大小”中的設(shè)置為準(zhǔn),單位:px 1.5.0
SDKVersion 客戶端基礎(chǔ)庫(kù)版本 1.1.0


示例代碼:

wx.getSystemInfo({
success: function(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)

}
})

wx.getSystemInfoSync()

獲取系統(tǒng)信息同步接口

同步返回參數(shù)說(shuō)明:

參數(shù) 說(shuō)明 最低版本
model 手機(jī)型號(hào)  
pixelRatio 設(shè)備像素比  
screenWidth 屏幕寬度 1.1.0
screenHeight 屏幕高度 1.1.0
windowWidth 可使用窗口寬度  
windowHeight 可使用窗口高度  
language 微信設(shè)置的語(yǔ)言  
version 微信版本號(hào)  
system 操作系統(tǒng)版本  
platform 客戶端平臺(tái)  
SDKVersion 客戶端基礎(chǔ)庫(kù)版本 1.1.0

示例代碼:

try {
var 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.canIUse(String)

判斷小程序的API,回調(diào),參數(shù),組件等是否在當(dāng)前版本可用。

String參數(shù)說(shuō)明: 使用${API}.${method}.${param}.${options}或者${component}.${attribute}.${option}方式來(lái)調(diào)用,例如:

  • ${API}代表 API 名字
  • ${method}代表調(diào)用方式,有效值為returnsuccessobjectcallback
  • ${param}代表參數(shù)或者返回值
  • ${options}代表參數(shù)的可選值
  • ${component}代表組件名字
  • ${attribute}代表組件屬性
  • ${option}代表組件屬性的可選值

例子:

wx.canIUse('openBluetoothAdapter')wx.canIUse('getSystemInfoSync.return.screenWidth')
wx.canIUse('getSystemInfo.success.screenWidth')
wx.canIUse('showToast.object.image')
wx.canIUse('onCompassChange.callback.direction')
wx.canIUse('request.object.method.GET')
wx.canIUse('contact-button')
wx.canIUse('text.selectable')
wx.canIUse('button.open-type.contact')


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)