React Native获取设备信息组件
生活随笔
收集整理的這篇文章主要介紹了
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.pngimage.png
image.png
組件地址
該組件的詳細說明和示例可以進入GitHub查看。
GitHub地址:https://github.com/rebeccahughes/react-native-device-info
舉手之勞關注我的微信公眾號:ReactNative開發圈
作者:forrest23
鏈接:https://www.jianshu.com/p/907b003835dc
來源:簡書
簡書著作權歸作者所有,任何形式的轉載都請聯系作者獲得授權并注明出處。
總結
以上是生活随笔為你收集整理的React Native获取设备信息组件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微博注册页面html,微博静态模板htm
- 下一篇: Vlan和vtp重要的配置命令