本文編輯: 技術藍天瀏覽 5106
版權所有,嚴禁轉載
獲取系統信息接口和獲取系統同步信息接口。
接口 | 說明 |
---|---|
wx.getSystemInfo(OBJECT) | 獲取系統信息。 |
wx.getSystemInfoSync() | 獲取系統信息同步接口 |
【代碼】
wxml
<button type="default" bindtap="getSystemInfo">獲取系統信息</button>
<button type="primary" bindtap="getSystemInfoSync">獲取系統信息同步</button>
js
getSystemInfo : function(){
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)
}
})
}
【代碼】
wxml
<button type="default" bindtap="getSystemInfo">獲取系統信息</button>
<button type="primary" bindtap="getSystemInfoSync">獲取系統信息同步</button>
js
getSystemInfoSync : function(){
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)
}
【wx.getSystemInfo(OBJECT)】:【獲取系統信息。】
【方法內容描述】
參數 | 類型 | 必填 | 描述 |
---|---|---|---|
success | Function | 是 | 接口調用成功的回調 |
fail | Function | 否 | 接口調用失敗的回調函數 |
fail | Function | 否 | 接口調用結束的回調函數(調用成功、失敗都會執行) |
success返回參數說明:
屬性 | 說明 |
---|---|
model | 手機型號 |
pixelRatio | 設備像素比 |
windowWidth | 窗口寬度 |
windowHeight | 窗口高度 |
language | 微信設置的語言 |
version | 微信版本號 |
system | 操作系統版本 |
platform | 客戶端平臺 |
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()】:【獲取系統信息同步接口。】
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
}