一、js直接调用wx.getSystemInfoSync
Page({
data: {
isIPhoneX:false,
},
onLoad: function () {
this.setData({
"isIphoneX": this.isIphoneX()
})
},
isIphoneX() {
let res = wx.getSystemInfoSync();
if (res.screenHeight == 812 || res.screenHeight == 896) {
return true;
} else {
return false;
}
}
})
二、调用wx.getSystemInfoSync
wx.getSystemInfo({
success: function (res) {
var safeBottom = res.screenHeight - res.safeArea.bottom
that.kBottomSafeHeight = safeBottom
//根据安全高度判断
if (safeBottom === 34) {
that.globalData.isIPhoneX = true
that.isIPhoneX = true
}
// // 根据 model 进行判断
// if (res.model.search('iPhone X') != -1) {
// that.globalData.isIPhoneX = true
// that.isIPhoneX = true
// }
// // 或者根据 screenHeight 进行判断
// if (res.screenHeight == 812 || res.screenHeight == 896) {
// that.isIPhoneX = true
// }
}
})