微信小程序使用wx.getSystemInfo()接口獲取系統信息[systemInfo]

微信小程序獲取系統信息的API:

回調參數:Object res

屬性 類型 說明 最低版本
brand string 設備品牌 1.5.0
model string 設備型號  
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 客戶端平臺  
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
bluetoothEnabled boolean 藍牙的系統開關 2.6.0
locationEnabled boolean 地理位置的系統開關 2.6.0
wifiEnabled boolean Wi-Fi 的系統開關 2.6.0
safeArea Object 在豎屏正方向下的安全區域 2.7.0

index.wxml示例代碼:

<!--index.wxml-->
<view class="container">
  <button bindtap='getInfo'>獲取系統信息</button>
  <view wx:if="{{model !=''}}">
    <view>手機型號:{{model}}</view>
    <view>設備像素比:{{pixelRatio}}</view>
    <view>窗口寬度:{{windowWidth}}</view>
    <view>窗口高度:{{windowHeight}}</view>
    <view>微信設置的語言:{{language}}</view>
    <view>微信版本號:{{version}}</view>
    <view>操作系統版本:{{system}}</view>
    <view>客戶端平臺:{{platform}}</view>
  </view>
</view>

index.js示例代碼一:wx.getSystemInfo(Object object)

//index.js
//獲取應用實例
const app = getApp()

Page({
  data: {
    model: '',
    pixelRatio: '',
    windowWidth: '',
    windowHeight: '',
    language: '',
    version: '',
    system: '',
    platform: ''
  },
  onLoad: function () {
  },
  getInfo: function () {
    var _this = this;
    wx.getSystemInfo({
      success: function (res) {
        _this.setData({
          model: res.model,
          pixelRatio: res.pixelRatio,
          windowWidth: res.windowWidth,
          windowHeight: res.windowHeight,
          language: res.language,
          version: res.version,
          system: res.system,
          platform: res.platform
        })
      },
      fail: function (res) {

      },
      complete: function (res) {

      }
    })
  }
})

index.js示例代碼二:wx.getSystemInfoSync()

//index.js
//獲取應用實例
const app = getApp()

Page({
  data: {
    model: '',
    pixelRatio: '',
    windowWidth: '',
    windowHeight: '',
    language: '',
    version: '',
    system: '',
    platform: ''
  },
  onLoad: function () {
  },
  getInfo: function () {
    var _this = this;
    try {
      var res = wx.getSystemInfoSync()
      _this.setData({
        model: res.model,
        pixelRatio: res.pixelRatio,
        windowWidth: res.windowWidth,
        windowHeight: res.windowHeight,
        language: res.language,
        version: res.version,
        system: res.system,
        platform: res.platform
      })
    } catch (e) {

    }
  }
})

效果展示圖:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章