这次介绍的获取移动设备信息的组件名叫:react-native-device-info,兼容IOS和安卓双平台,可以获取设备ID、设备品牌、设备型号、IP以及APP版本号等信息。是一个应用很广泛的基础组件。
安装
npm install --save react-native-device-info
注:如果React Naitve的版本大于0.47,那么需要使用>=0.11版本的react-native-device-info组件
因为涉及到原生代码,所以在执行完install后,需要执行 命令react-native react-native-device-info
使用示例
import DeviceInfo from \'react-native-device-info\';
const device = {};
device.DeviceID = deviceInfo.getUniqueID();
device.UserAgent = deviceInfo.getUserAgent();
device.DeviceBrand = deviceInfo.getBrand();
device.DeviceModel = deviceInfo.getModel();
device.SystemVersion = deviceInfo.getSystemVersion();
device.AppVersion = deviceInfo.getVersion();
device.AppReadableVersion = deviceInfo.getReadableVersion();
该组件使用也很方便,直接import后,直接调用相应的方法即可。但是有一个方法比较特殊就是isPinOrFingerprintSet方法,需要使用异步的方式来调。代码如下:
import DeviceInfo from \'react-native-device-info\';
DeviceInfo.isPinOrFingerprintSet()(isPinOrFingerprintSet => {
if (!isPinOrFingerprintSet) {
...
}
}
此篇文章是转载的
作者:forrest23
链接:https://www.jianshu.com/p/907b003835dc
來源:简书
继续阅读与本文标签相同的文章
上一篇 :
BZOJ 2733: [HNOI2012]永无乡
下一篇 :
高端网站制作进行网站页面设计分析时,你要看清三点
-
深入理解 Java 中 SPI 机制
2026-05-18栏目: 教程
-
阿里云“网红"运维工程师白金:做一个平凡的圆梦人
2026-05-18栏目: 教程
-
使用nginx部署网站
2026-05-18栏目: 教程
-
Java的四种线程池的使用,以及自定义线程工厂
2026-05-18栏目: 教程
-
Leetcode之删除排序数组中的重复项
2026-05-18栏目: 教程
