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
|