1, access device model
App({
// 全局数据
globalData: {
// 其他数据定义 ...
isIPX: false, // 当前设备是否为 iPhone X
},
// 小程序启动入口
onLaunch: function (options) {
// 其他启动代码...
// 判断设备是否为 iPhone X
this.checkIsIPhoneX()
},
checkIsIPhoneX: function() {
const self = this
wx.getSystemInfo({
success: function (res) {
// 根据 model 进行判断
if (res.model.search('iPhone X') != -1) {
self.globalData.isIPX = true
}
// 或者根据 screenHeight 进行判断
// if (res.screenHeight == 812) {
// self.globalData.isIPX = true
// }
}
})
},
NOTE:
Note that there is a pit, in the micro-channel simulator developer tools, if the selection is iPhone X, the model is acquired at this time iPhone X, resulting in a real machine is I think this value, then directly IF (model == 'iPhone X') is determined, but in fact the real machine model value of this format: iPhone X (GSM + CDMA) <iPhone10,3>, so we need to be determined by matching the character string retrieval