React-native-device-info 是一个在React Native中获取移动设备信息的第三方库
安装 : yarn add react-native-device-info
链接原生代码库: react-native link react-native-device-info
引入组件
import DeviceInfo from 'react-native-device-info';
//获取API版本
const apiLevel = DeviceInfo.getAPILevel();
//获取App应用名称
const appName = DeviceInfo.getApplicationName();
//获取设备品牌类型
const brand = DeviceInfo.getBrand();
//获取应用包名
const bundleId = DeviceInfo.getBundleId();
//获取设备mac地址,需要配置权限,如Android需要在原生项目中中配置
// <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
DeviceInfo.getMACAddress().then(mac => {
consle.log(mac);
});
//获取设备ip地址,需配置权限,同上
DeviceInfo.getIPAddress().then(ip => {
alert(ip);
});
//获取设备唯一的ID
const uniqueID = DeviceInfo.getUniqueID();
//获取应用版本号,Android中对应versionName
const versionName = DeviceInfo.getVersion();
// 获取应用编译版本号,Android中对应versionCode
const versionCode = getBuildNumber();
该组件的其他方法详细说明和示例可以进入官方GitHub地址查看,https://github.com/rebeccahughes/react-native-device-info
使用React-native-device-info获取移动设备信息

本文介绍了如何在React Native应用中使用react-native-device-info库来获取设备的API级别、应用名称、品牌、包名、MAC地址、IP地址、唯一ID、版本号和编译版本号等信息。通过安装、链接库以及调用相应方法,可以实现对设备信息的全面获取。
718

被折叠的 条评论
为什么被折叠?



