Android 和 iOS 平台不支持通过条件编译来区分

使用uni-app开发时候,区分 Android、iOS
平台,需要uni-app提供的API:uni.getSystemInfo和uni.getSystemInfoSync()

1.调用uni.getSystemInfo 来获取平台信息。
2.代码已经打入包中,仍然需要在代码运行期分析运行环境,此时可使用uni.getSystemInfoSync().platform判断客户端环境是
Android、iOS 还是小程序开发工具
3.在百度小程序开发工具、微信小程序开发工具、支付宝小程序开发工具中使用uni.getSystemInfoSync().platform返回值均为
devtools
switch(uni.getSystemInfoSync().platform){ case 'android': console.log(
'运行Android上') break; case 'ios': console.log('运行iOS上') break; default: console.
log('运行在开发者工具上') break; }
如有必要,也可以在条件编译里自己定义一个变量,赋不同值。在后续运行代码中动态判断环境。
<template> <view> <view v-if="isIosApp"> IOS-APP端 </view> <view v-else> 非IOS-
APP端 </view> </view> </template> <script> export default { data() { return { //
判断是否为ios的的APP端 isIosApp: false, } }, onLoad() { // #ifdef APP-PLUS this.isIosApp
=uni.getSystemInfoSync().platform === 'ios' // #endif }, } </script>

技术
今日推荐
PPT
阅读数 131
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信