注冊

微信小程序API系統(tǒng)信息,wx.getSystemInfo獲取系統(tǒng)信息

2020-09-27
導讀:wx.getSystemInfo(OBJECT) 獲取系統(tǒng)信息。 OBJECT參數(shù)說明: 參數(shù) 類型 必填 說明 success Function 是 接口調(diào)用成功的回調(diào) fail Function 否 接口調(diào)用失敗的回調(diào)函數(shù) complete Function 否 接口調(diào)用結(jié)束的回...

 

wx.getSystemInfo(OBJECT)

微信小程序API系統(tǒng)信息,wx.getSystemInfo獲取系統(tǒng)信息


 

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

OBJECT參數(shù)說明:

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

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

 

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

參數(shù) 說明 最低版本
model 手機型號  
pixelRatio 設(shè)備像素比  
screenWidth 屏幕寬度 1.1.0
screenHeight 屏幕高度 1.1.0
windowWidth 可使用窗口寬度  
windowHeight 可使用窗口高度  
language 微信設(shè)置的語言  
version 微信版本號  
system 操作系統(tǒng)版本  
platform 客戶端平臺  
SDKVersion 客戶端基礎(chǔ)庫版本 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ù),組件等是否在當前版本可用。

String參數(shù)說明: 使用${API}.${method}.${param}.${options}或者${component}.${attribute}.${option}方式來調(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')

 

更多微信小程序開發(fā)教程,可以關(guān)注hi小程序。
重磅推薦:小程序開店目錄

第一部分:小商店是什么

第二部分:如何開通一個小商店

第三部分:如何登錄小商店

第四部分:開店任務(wù)常見問題

第五部分:小商店可以賣什么

第六部分:HiShop小程序特色功能

第七部分:小程序直播

第八部分:小程序收貨/物流

第九部分:小程序怎么結(jié)算

第十部分:小程序客服

第十一部分:電商創(chuàng)業(yè)

第十二部分:小程序游戲開發(fā)