React-native-device-info获取设备信息

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:45   1213   0

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

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP