
简体中文
判断当前是否是模拟器,Android设备上会采集传感器信息。
从4.51+,uni.getDeviceInfo里的isSimulator由于隐私政策原因,去掉了访问传感器列表。独立了一个单独的uni.isSimulator
。
本API可以根据传感器的信息更准确的识别是否为模拟器。但本API在Android平台上线应用商店时,务必注意需要在隐私协议中声明,并确保在隐私协议被用户同意后再调用。
有些模拟器会故意伪装真机,此时可能识别不准确。
iOS平台请暂时继续使用uni.getDeviceInfo
Web | 微信小程序 | Android | iOS |
---|---|---|---|
x | x | 4.51 | x |
类型 |
---|
boolean |
该 API 不支持 Web,请运行 hello uni-app x 到 App 平台体验
<template>
<!-- #ifdef APP -->
<scroll-view style="flex:1">
<!-- #endif -->
<view>
<page-head :title="'isSimulator'"></page-head>
<view class="uni-common-mt" style="flex-direction: row;justify-content: center;">
<text class="">{{
isSimulator ? "当前设备是模拟器" : "当前设备不是模拟器"
}}</text>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script setup>
const isSimulator = ref(false)
isSimulator.value = uni.isSimulator()
</script>
<style>
</style>
该 API 不支持 Web,请运行 hello uni-app x 到 App 平台体验
<template>
<!-- #ifdef APP -->
<scroll-view style="flex:1">
<!-- #endif -->
<view>
<page-head :title="'isSimulator'"></page-head>
<view class="uni-common-mt" style="flex-direction: row;justify-content: center;">
<text class="">{{
isSimulator ? "当前设备是模拟器" : "当前设备不是模拟器"
}}</text>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script setup>
const isSimulator = ref(false)
isSimulator.value = uni.isSimulator()
</script>
<style>
</style>
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
---|---|---|---|---|---|
errMsg | string | 是 | - | 错误信息 |