首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在react-native中检测设备操作系统(不使用平台api)

在react-native中检测设备操作系统(不使用平台api)
EN

Stack Overflow用户
提问于 2021-07-04 21:40:50
回答 3查看 63关注 0票数 1

我正在尝试检测这个应用程序是运行在安卓还是androidTV上,因为我问here的问题,我不能使用react-native's platform api

有没有其他的包可以让我这样做呢?或者我可以用javascript自己写?

EN

回答 3

Stack Overflow用户

发布于 2021-07-04 22:50:50

您可以从react-native-device-info https://github.com/react-native-device-info/react-native-device-info#getDeviceType使用getDeviceType helper

代码语言:javascript
运行
复制
import React from 'react';
import { View, Text } from 'react-native';
import { getDeviceType } from 'react-native-device-info';

const deviceType = getDeviceType();

const App = () => {
  return (
    <View>
      <Text>{deviceType}</Text>
    </View>
  );
};

export default App;
票数 0
EN

Stack Overflow用户

发布于 2021-07-05 05:54:17

我不知道这是否会解决您的特定用例,但您可以通过在文件名中指定每个平台的特定文件:

代码语言:javascript
运行
复制
index.android.js
index.ios.js

React native将根据平台选择要使用的文件。

票数 0
EN

Stack Overflow用户

发布于 2021-08-05 13:45:47

尝试来自React Native的平台模块

代码语言:javascript
运行
复制
import { Platform } from "react-native"

isTV === Platform.constants.uiMode === "tv"

https://reactnative.dev/docs/platform#properties

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68245286

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档