Back to Uni App

Is Simulator

docs/api/is-simulator.md

2.3.35.2 KB
Original Source
<!-- ## uni.isSimulator() @issimulator -->

::: sourceCode

uni.isSimulator() @issimulator

GitCode: https://gitcode.com/dcloud/uni-api/tree/alpha/uni_modules/uni-getDeviceInfo

GitHub: https://github.com/dcloudio/uni-api/tree/alpha/uni_modules/uni-getDeviceInfo

:::

判断当前是否是模拟器,Android设备上会采集传感器信息。

从4.51+,uni.getDeviceInfo里的isSimulator由于隐私政策原因,去掉了访问传感器列表。独立了一个单独的uni.isSimulator

本API可以根据传感器的信息更准确的识别是否为模拟器。但本API在Android平台上线应用商店时,务必注意需要在隐私协议中声明,并确保在隐私协议被用户同意后再调用。

有些模拟器会故意伪装真机,此时可能识别不准确。

iOS平台请暂时继续使用uni.getDeviceInfo

isSimulator 兼容性

Web微信小程序AndroidiOSHarmonyOS
<a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a><a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a>4.514.51<a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a>

返回值

类型
boolean

示例

示例为hello uni-app x alpha分支,与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例另见

该 API 不支持 Web,请运行 hello uni-app x 到 App 平台体验

::: preview

appRedirect https://hellouniappx.dcloud.net.cn/appredirect.html?path=pages/API/is-simulator/is-simulator

uvue
<template>
  <!-- #ifdef APP -->
  <scroll-view style="flex:1">
  <!-- #endif -->
    <view>
      <page-head :title="'isSimulator'"></page-head>
      <view class="uni-common-mt" style="justify-content: center;align-items: center;">
        <text>{{
		        isSimulator ? "当前设备是模拟器" : "当前设备不是模拟器"
		      }}</text>
        <text>\n注:有些模拟器会故意伪装为真机,此时识别可能会不准确</text>
      </view>
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

<script setup>
  const isSimulator = ref(false)
  isSimulator.value = uni.isSimulator()
</script>

<style>

</style>

:::

参见

示例

示例为hello uni-app x alpha分支,与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例另见

该 API 不支持 Web,请运行 hello uni-app x 到 App 平台体验

::: preview

appRedirect https://hellouniappx.dcloud.net.cn/appredirect.html?path=pages/API/is-simulator/is-simulator

uvue
<template>
  <!-- #ifdef APP -->
  <scroll-view style="flex:1">
  <!-- #endif -->
    <view>
      <page-head :title="'isSimulator'"></page-head>
      <view class="uni-common-mt" style="justify-content: center;align-items: center;">
        <text>{{
		        isSimulator ? "当前设备是模拟器" : "当前设备不是模拟器"
		      }}</text>
        <text>\n注:有些模拟器会故意伪装为真机,此时识别可能会不准确</text>
      </view>
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

<script setup>
  const isSimulator = ref(false)
  isSimulator.value = uni.isSimulator()
</script>

<style>

</style>

:::

通用类型

GeneralCallbackResult

名称类型必备默认值兼容性描述
errMsgstring-Web: -; 微信小程序: 4.41; Android: -; iOS: -; HarmonyOS: -错误信息