微信小程序判斷手機平臺,獲取手機信息

// pages/sysinfo/sysinfo.js
var app = getApp()
Page({

    /**
     * 頁面的初始數據
     */
    data: {
        sysinfotest:""
    },

    /**
     * 生命週期函數--監聽頁面加載
     */
    onLoad: function (options) {
        var that=this;
        wx.getSystemInfo({
        success: function(res) {
        that.setData({
        sysinfotest:JSON.stringify(res)
        })
        console.log("res:"+that.data.sysinfotest)
        //獲取res.platform進行判斷即可
        console.log("手機平臺:"+res.platform)
         }
        })
    },

 

獲取的數據如下

紅米k20pro

res:{
    "locationEnabled": true,
    "screenWidth": 393,
    "benchmarkLevel": 9,
    "screenHeight": 851,
    "windowHeight": 769,
    "bluetoothEnabled": true,
    "errMsg": "getSystemInfo:ok",
    "language": "zh_CN",
    "microphoneAuthorized": true,
    "version": "7.0.12",
    "cameraAuthorized": true,
    "system": "Android 10",
    "fontSizeSetting": 16,
    "locationAuthorized": true,
    "pixelRatio": 2.75,
    "notificationAuthorized": true,
    "model": "Redmi K20 Pro",
    "statusBarHeight": 35,
    "deviceOrientation": "portrait",
    "wifiEnabled": false,
    "safeArea": {
        "width": 393,
        "right": 393,
        "top": 0,
        "left": 0,
        "bottom": 851,
        "height": 851
    },
    "brand": "Xiaomi",
    "windowWidth": 393,
    "screenTop": 83,
    "platform": "android",
    "SDKVersion": "2.10.3",
    "devicePixelRatio": 2.75
}

手機平臺:android

 

iphone7:

res:{
    "language": "zh_CN",
    "wifiEnabled": true,
    "safeArea": {
        "bottom": 667,
        "height": 647,
        "top": 20,
        "width": 375,
        "left": 0,
        "right": 375
    },
    "bluetoothEnabled": true,
    "locationAuthorized": true,
    "deviceOrientation": "portrait",
    "notificationSoundAuthorized": true,
    "screenHeight": 667,
    "windowHeight": 603,
    "version": "7.0.10",
    "fontSizeSetting": 17,
    "system": "iOS 13.3.1",
    "notificationAuthorized": true,
    "statusBarHeight": 20,
    "pixelRatio": 2,
    "windowWidth": 375,
    "notificationBadgeAuthorized": true,
    "errMsg": "getSystemInfo:ok",
    "locationEnabled": true,
    "model": "iPhone 7<iPhone9,3>",
    "batteryLevel": 95,
    "screenWidth": 375,
    "screenTop": 0,
    "microphoneAuthorized": true,
    "cameraAuthorized": true,
    "albumAuthorized": true,
    "notificationAlertAuthorized": true,
    "brand": "iPhone",
    "platform": "ios",
    "SDKVersion": "2.10.3",
    "devicePixelRatio": 2
}

手機平臺:ios

 

 

 

 

 

 

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