react-native获取设备信息组件(react-native-device-info)
一、组件说明:
该组件同时适配Android和IOS平台。
二、组件介绍
1.首先需要安装组件:npm install react-native-device-info --save
2.IOS初始化:打开Xcode——>右击Libraries——>选择文件到当前项目,进入到node_modules/react-native-device-info——>添加.xcodeproj文件
2.1.在Xcode中点击你的工程名字——>Build Phases——>Link Binary With Libraries——>点击 '+'号按钮,添加libRNDeviceInfo.a文件(如下图所示)

2.2.添加环境变量:$(SRCROOT)/../react-native/React and $(SRCROOT)/../../React 并且修改 recursive
2.3.好了,下面就是基本的用法了
import DeviceInfo from 'react-native-device-info'
console.log("Device Unique ID", DeviceInfo.getUniqueID()); // e.g. FCDBD8EF-62FC-4ECB-B2F5-92C9E79AC7F9
// * note this is IDFV on iOS so it will change if all apps from the current apps vendor have been previously uninstalled console.log("Device Manufacturer", DeviceInfo.getManufacturer()); // e.g. Apple console.log("Device Model", DeviceInfo.getModel()); // e.g. iPhone 6 console.log("Device ID", DeviceInfo.getDeviceId()); // e.g. iPhone7,2 / or the board on Android e.g. goldfish console.log("Device Name", DeviceInfo.getSystemName()); // e.g. iPhone OS console.log("Device Version", DeviceInfo.getSystemVersion()); // e.g. 9.0 console.log("Bundle Id", DeviceInfo.getBundleId()); // e.g. com.learnium.mobile console.log("Build Number", DeviceInfo.getBuildNumber()); // e.g. 89 console.log("App Version", DeviceInfo.getVersion()); // e.g. 1.1.0 console.log("App Version (Readable)", DeviceInfo.getReadableVersion()); // e.g. 1.1.0.89 console.log("Device Name", DeviceInfo.getDeviceName()); // e.g. Becca's iPhone 6 console.log("User Agent", DeviceInfo.getUserAgent()); // e.g. Dalvik/2.1.0 (Linux; U; Android 5.1; Google Nexus 4 - 5.1.0 - API 22 - 768x1280 Build/LMY47D) console.log("Device Locale", DeviceInfo.getDeviceLocale()); // e.g en-US console.log("Device Country", DeviceInfo.getDeviceCountry()); // e.g US
3.Android的安装:
3.1首先需要修改下Gradle文件
在你的根目录下运行:react-native link react-native-device-info
3.2在MainActivity.java文件中进行注册模块(react-native的版本需要>0.18)
import com.learnium.RNDeviceInfo.RNDeviceInfo; // <--- import
public class MainActivity extends ReactActivity {
......
/**
* A list of packages used by the app. If the app uses additional views
* or modules besides the default ones, add more packages here.
*/
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new RNDeviceInfo(), // <------ add here
new MainReactPackage());
}
}
3.3如果你需要在安卓上获取设备的名字,需要修改AndroidManifest.xml配置文件,来获取权限。
...
<uses-permission android:name="android.permission.BLUETOOTH"/>
3.4用法同IOS。
翻译链接:https://github.com/rebeccahughes/react-native-device-info
react-native获取设备信息组件(react-native-device-info)的更多相关文章
- React Native(五)——获取设备信息react-native-device-info
心酸史: 自从接触rn开始后,越来越多的引入第三方组件而开始的配置文件,让自己一再头疼: 明明是按照官方文档一步一步的配置,为什么别人可以做到的自己却屡屡出错,真是哭笑不得--从微信分享react-n ...
- C#使用Xamarin开发可移植移动应用终章(11.获取设备信息与常用组件,开源一个可开发模版.)
前言 系列目录 C#使用Xamarin开发可移植移动应用目录 源码地址:https://github.com/l2999019/DemoApp 可以Star一下,随意 - - 说点什么.. 本系列,终 ...
- ios获取设备信息总结
1.获取设备的信息 UIDevice *device = [[UIDevice alloc] int]; NSString *name = device.name; //获取设备所有者的名 ...
- Android 获取设备信息 异常
/**获取设备信息 * @param c * @return */ public static void setDeviceInfo(Context c,RequestParams params){ ...
- 微信小程序 --- 获取设备信息
获取设备信息: wx.getSystemInfo model:手机型号 pixelRatio:设备像素比 windowWidth:窗口宽度 windowHeight:窗口高度 language:语言 ...
- PhoneGap获取设备信息
一. 获取设备信息的方法列表(如果没有或者检测不出来就显示undefined) 1.device.name 设备名称(一些国产机检测不出来) 2.device.model ...
- appium自动化测试框架——封装获取设备信息类
在上一节中,我们已经解决了如何在python中执行cmd,并获取执行结果.下面就小小实战一下,获取设备信息. 一.思路 1.windows上获取设备信息的方法 输入dos命令“adb devices” ...
- 小白学phoneGap《构建跨平台APP:phoneGap移动应用实战》连载五(使用PhoneGap获取设备信息)
除了能够将HTML页面打包成可以直接安装运行的APP外,PhoneGap的一个最大优势在于可以通过JavaScript调用设备来访问设备上的硬件信息,从而实现一些原本只有依靠原生SDK才能够达到的目的 ...
- 微信小程序把玩(三十八)获取设备信息 API
原文:微信小程序把玩(三十八)获取设备信息 API 获取设备信息这里分为四种, 主要属性: 网络信息wx.getNetWorkType, 系统信息wx.getSystemInfo, 重力感应数据wx. ...
随机推荐
- Tomcat设计模式
omcat 系统架构与设计模式,第 2 部分 设计模式分析 系列内容: 此内容是该系列 2 部分中的第 2 部分: Tomcat 系统架构与设计模式 门面设计模式 门面设计模式在 Tomcat 中有多 ...
- Hive SQL 分类
题目: 请使用Hive SQL实现下面的题目. 下面是一张表名为user_buy_log的表,有三个字段,user(用户),grp(分组编号),time(购物时间). 需要将用户按照grp分组,对ti ...
- Matlab中hold on与hold off的用法
摘录自:https://blog.csdn.net/smf0504/article/details/51830963 https://www.cnblogs.com/shuqingstudy/p/48 ...
- 中间件方法必须返回Response对象实例(tp5.1+小程序结合时候出的问题)
前言:在最近开发小程序通过中间件检查是否携带token时候报的一个错误 解决方法: 根据手册中需要return出去才可以不报错
- [物理学与PDEs]第3章习题5 一维理想磁流体力学方程组的数学结构
试将一维理想磁流体力学方程组 (5. 10)-(5. 16) 化为一阶拟线性对称双曲组的形式. 解答: 由 (5. 12),(5. 16) 知 $$\beex \bea 0&=\cfrac{\ ...
- MacOS下使用远程桌面VNC
1 分为一个server 和 viewer,server端就是可以加入组然后允许远程连接,viewer就是远程连接端 2 server下载地址 https://www.realvnc.com/en/c ...
- webpack构建Vue工程
先开始webpack基本构建 创建一个工程目录 vue-structure mkdir vue-structure && cd vue-structure 安装webpack ...
- 6-12 varchar和char 枚举类型enum 集合set
1 字符类型char和varchar #官网:https://dev.mysql.com/doc/refman/5.7/en/char.html #注意:char和varchar括号内的参 ...
- L1-Day3
L1-Day31.太阳从西边落下. [我的翻译]The sun falls in the west. [标准答案]The sun sets in the west. [对比分析]落下fall与set的 ...
- Linux下tar bz gz等压缩包的压缩和解压【转】
Linux下用户经常需要备份计算机系统中的数据,为了节省存储空间,常常将备份文件进行压缩,本文是对压缩和解压命令的大致总结 .tar.gz 解压:tar zxvf FileName.tar.gz ...