<!--pages/API/DeviceInfo/index.wxml-->
<view class='box'>
  <view class='title'>{{msg}}获取您的设备信息</view>
  <view class='border' hidden='{{hide1}}'>
    <view>手机型号:{{model}}</view>
    <view>设备像素比:{{pixelRatio}}</view>
    <view>屏幕宽度:{{screenWidth}}</view>
    <view>屏幕高度:{{screenHeight}}</view>
    <view>窗口宽度:{{windowWidth}}</view>
    <view>窗口高度:{{windowHeight}}</view>
    <view>微信语言:{{language}}</view>
    <view>微信版本:{{version}}</view>
    <view>操作系统版本:{{system}}</view>
    <view>客户端平台:{{platform}}</view>
    <view>客户端基础库版本:{{SDKVersion}}</view>
  </view>

  <view class='border' hidden='{{hide2}}'>
    <view>手机型号:{{model}}</view>
    <view>设备像素比:{{pixelRatio}}</view>
    <view>屏幕宽度:{{screenWidth}}</view>
    <view>屏幕高度:{{screenHeight}}</view>
    <view>窗口宽度:{{windowWidth}}</view>
    <view>窗口高度:{{windowHeight}}</view>
    <view>微信语言:{{language}}</view>
    <view>微信版本:{{version}}</view>
    <view>操作系统版本:{{system}}</view>
    <view>客户端平台:{{platform}}</view>
    <view>客户端基础库版本:{{SDKVersion}}</view>
  </view>
  <view class='btnLayout'>
    <button type='primary' bindtap='getSystemInfoSync'>同步获取</button>
    <button type='primary' bindtap='getSystemInfo'>异步获取</button>
  </view>
</view>
/* pages/API/DeviceInfo/index.wxss */

.border {
  border: 1px solid seagreen;
}

view {
  margin: 8px;
}

.btnLayout {
  display: flex;
  flex-direction: row;
  justify-content: space-around;
}

button {
  width: 45%;
  margin: 5px;
}
// pages/API/DeviceInfo/index.js
Page({
  data: {
    hide1: false,
    hide2: true
  },
  getSystemInfo: function() { //异步获取设备信息
    var that = this;
    wx.getSystemInfo({
      success: (res) => {
        that.setData({
          msg: '异步',
          hide1: false,
          hide2: true,
          model: res.model,
          pixelRatio: res.pixelRatio,
          screenWidth: res.screenWidth,
          screenHeight: res.screenHeight,
          windowWidth: res.windowWidth,
          windowHeight: res.windowHeight,
          language: res.language,
          version: res.version,
          system: res.system,
          platform: res.platform,
          SDKVersion: res.SDKVersion
        })
      },
    })
  },

  getSystemInfoSync: function() {
    var that = this;
    try {
      var res = wx.getSystemInfoSync();
      that.setData({
        msg: '同步',
        hide1: true,
        hide2: false,
        model: res.model,
        pixelRatio: res.pixelRatio,
        screenWidth: res.screenWidth,
        screenHeight: res.screenHeight,
        windowWidth: res.windowWidth,
        windowHeight: res.windowHeight,
        language: res.language,
        version: res.version,
        system: res.system,
        platform: res.platform,
        SDKVersion: res.SDKVersion
      })
    } catch (e) {
      console.log(e)
    }
  }

})

异步获取设备系统信息

  wx.getSystemInfo(Object object) 异 步 获 取 设 备 系统信息,参数属性只包含success、fail和complete 三个回调函数。

success 回调函数参数的主要属性

  

  

同步获取设备系统信息

  Object wx.getSystemInfoSync() 同步获取设备 系统信息,其返回值的主要属性与上表一致