【发布时间】:2019-09-07 07:56:22
【问题描述】:
我想在我的应用中显示 Android 版本(如 8.0、9.0...)。现在我正在使用:Platform.Version 但这会返回 API 版本(24、25...)。
我想要一个比创建映射更优雅的选项,并且不需要每次有新的 android 版本时都重新发布。 有没有办法在没有外部库的情况下做到这一点?
【问题讨论】:
标签: javascript reactjs react-native native
我想在我的应用中显示 Android 版本(如 8.0、9.0...)。现在我正在使用:Platform.Version 但这会返回 API 版本(24、25...)。
我想要一个比创建映射更优雅的选项,并且不需要每次有新的 android 版本时都重新发布。 有没有办法在没有外部库的情况下做到这一点?
【问题讨论】:
标签: javascript reactjs react-native native
你可以使用这个库,
import DeviceInfo from "react-native-device-info";
DeviceInfo.getSystemVersion()
除了版本之外,它还有很多方法可以方便地获取设备特定信息。
编辑:是getSystemVersion()
【讨论】:
getVerison() 不打印 android 版本本身。它打印应用程序版本。
你有两个选择
Platform.Version 映射您获得的值。使用 3rd 方库,例如 react-native-device-info、getSystemVersion
DeviceInfo.getSystemVersion()
【讨论】:
你好检查这个组件
react-native-device-info
**Gets the API level.**
**Examples**
getAPILevel()
const apiLevel = DeviceInfo.getAPILevel();
// iOS: ?
// Android: 25
// Windows: ?
【讨论】:
您可以使用Platform.constants.Release
【讨论】:
TypeError: undefined is not an object (evaluating '_reactNative.Platform.Constants.Release')
你可以:
import { Platform } from 'react-native';
const OsVer = Platform.constants['Release'];
【讨论】: