React Native获取设备信息组件

转载 https://www.jianshu.com/p/907b003835dc


本文原创首发于公众号:ReactNative开发圈,转载需注明出处。

这次介绍的获取移动设备信息的组件名叫: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后,需要执行link命令
react-native link 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) {
    ...
  }
}

方法列表

image.png

image.png

image.png

组件地址

该组件的详细说明和示例可以进入GitHub查看。
GitHub地址:https://github.com/rebeccahughes/react-native-device-info

举手之劳关注我的微信公众号:ReactNative开发圈



作者:forrest23
链接:https://www.jianshu.com/p/907b003835dc
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

猜你喜欢

转载自blog.csdn.net/james_laughing/article/details/80864250
今日推荐