微信小程序有时候需要知道运行的客户端是ios设备还是android设备 , 官方提供了可行的api , 官方文档 : https://developers.weixin.qq.com/miniprogram/dev/api/system/system-info/wx.getSystemInfo.html
具体方式如下:
const that = this;
wx.getSystemInfo({
success(res) {
if (res.platform == "ios") {
//ios平台
} else if (res.platform == "android") {
//android平台
} else if (res.platform == "devtools") {
//开发工具
}
},
fail(res) {},
complete() {},
})
此方法分为同步异步两个方法 , 分别为wx.getSystemInfoSync() 和wx.getSystemInfo() ;
注意getSystemInfo()回调方法中this的指代问题 .