Skip to content

微信小程序如何获取设备信息

🕒 Published at:
javascript
function ssss() {
  wx.getSystemInfo({
    success: (res) => {
      console.log(res, '====设备信息====')
      /* 属性  类型  说明
        brand  string  设备品牌
        model  string  设备型号
        pixelRatio  number  设备像素比
        screenWidth  number  屏幕宽度,单位px
        screenHeight  number  屏幕高度,单位px
        windowWidth  number  可使用窗口宽度,单位px
        windowHeight  number  可使用窗口高度,单位px
        statusBarHeight  number  状态栏的高度,单位px
        language  string  微信设置的语言
        version  string  微信版本号
        system  string  操作系统及版本
        platform  string  客户端平台
        fontSizeSetting  number  用户字体大小(单位px)。以微信客户端「我-设置-通用-字体大小」中的设置为准
        SDKVersion  string  客户端基础库版本
        benchmarkLevel  number  设备性能等级(仅 Android)。取值为:-2 或 0(该设备无法运行小游戏),-1(性能未知),>=1(设备性能值,该值越高,设备性能越好,目前最高不到50)  1.8.0
        albumAuthorized  boolean  允许微信使用相册的开关(仅 iOS 有效)
        cameraAuthorized  boolean  允许微信使用摄像头的开关
        locationAuthorized  boolean  允许微信使用定位的开关
        microphoneAuthorized  boolean  允许微信使用麦克风的开关
        notificationAuthorized  boolean  允许微信通知的开关
        notificationAlertAuthorized  boolean  允许微信通知带有提醒的开关(仅 iOS 有效)
        notificationBadgeAuthorized  boolean  允许微信通知带有标记的开关(仅 iOS 有效)
        notificationSoundAuthorized  boolean  允许微信通知带有声音的开关(仅 iOS 有效)
        bluetoothEnabled  boolean  蓝牙的系统开关
        locationEnabled  boolean  地理位置的系统开关
        wifiEnabled  boolean  Wi-Fi 的系统开关
        safeArea  Object  在竖屏正方向下的安全区域
        theme  string  系统当前主题,取值为light或dark,全局配置"darkmode":true时才能获取,否则为 undefined (不支持小游戏)
 */
    },
    fail: () => {},
    complete: () => {},
  })
}

最后:希望大家补充其它相关方法,分享是每一位程序员都要有的美德~

转载请注明出处!谢谢~ by:汪荣顶

Powered by 荣顶
|
Copyright © 2018-present
|
Released under the MIT License
|
Views: