微信小程序获取当前设备信息;微信小程序判断是iOS还是安卓

该代码段展示了如何利用微信小程序的wx.getSystemInfo接口获取设备信息,包括平台类型(如iOS或Android)、设备型号、屏幕尺寸、电池状态等。通过这些信息,开发者可以针对不同平台进行适配和优化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码

onLoad() {
	let that = this;
	 wx.getSystemInfo({
		 success:function(res){
			 console.log("wx.getSystemInfo")
			 console.log(res)
			 if(res.platform=="ios"){
				that.isIOS = !that.isIOS; 
			 }
		 }
	 });
}

如果是安卓,返回如下

在这里插入图片描述

如果是iOS返回如下

SDKVersion: "2.17.0"
albumAuthorized: true
batteryLevel: 27.000001907348633
benchmarkLevel: 15
bluetoothEnabled: true
brand: "iPhone"
cameraAuthorized: true
deviceOrientation: "portrait"
devicePixelRatio: 3
enableDebug: false
errMsg: "getSystemInfo:ok"
fontSizeSetting: 17
host: {env: "WeChat", appId: "", version: 402654252}
language: "zh_CN"
locationAuthorized: true
locationEnabled: true
locationReducedAccuracy: false
microphoneAuthorized: true
model: "iPhone 7 Plus<iPhone9,2>"
notificationAlertAuthorized: true
notificationAuthorized: true
notificationBadgeAuthorized: true
notificationSoundAuthorized: true
pixelRatio: 3
platform: "ios"
safeArea: {bottom: 736, height: 716, top: 20, width: 414, left: 0,}
screenHeight: 736
screenTop: 0
screenWidth: 414
statusBarHeight: 20
system: "iOS 13.7"
version: "8.0.4"
wifiEnabled: true
windowHeight: 672
windowWidth: 414

相关资料

wx.getSystemInfo(Object object)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值