uni-app获取设备系统是IOS还是Android
uni-app
2023-08-25 19:32:47
uni-app多端框架在前端开发中有着毋庸置疑的位置,基于uni-app开发的项目也随着人们对于uni-app的接受而逐渐增多。
那么基于uni-app多端框架要如何实现获取设备的系统呢?
本篇文章就来详细了解基于uni-app多端框架实现判断当前设备系统是什么?
代码如下:
const res = uni.getSystemInfoSync()
if(res.platform==='ios'){
return 'ios'
}else if(res.platform==='android'){
return 'android'
}else{
return 'other';
}
通过上述代码可知:主要使用的为uni-app提供的getSystemInfoSync。通过getSystemInfoSync可以获取系统信息,这其中就包含了设备系统。
platform:客户端平台,值域为:ios、android、mac(3.1.10+)、windows(3.1.10+)、linux(3.1.10+)
如上述代码所示,仅判断了ios和android。其余的系统可根据实际情况来进行添加if判断执行对应操作。

889篇文章
1740人已阅读