转载链接:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/react-native-acquisition-device-information-component-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)的更多相关文章

  1. React Native(五)——获取设备信息react-native-device-info

    心酸史: 自从接触rn开始后,越来越多的引入第三方组件而开始的配置文件,让自己一再头疼: 明明是按照官方文档一步一步的配置,为什么别人可以做到的自己却屡屡出错,真是哭笑不得--从微信分享react-n ...

  2. C#使用Xamarin开发可移植移动应用终章(11.获取设备信息与常用组件,开源一个可开发模版.)

    前言 系列目录 C#使用Xamarin开发可移植移动应用目录 源码地址:https://github.com/l2999019/DemoApp 可以Star一下,随意 - - 说点什么.. 本系列,终 ...

  3. ios获取设备信息总结

    1.获取设备的信息 UIDevice *device = [[UIDevice alloc] int]; NSString *name = device.name;       //获取设备所有者的名 ...

  4. Android 获取设备信息 异常

    /**获取设备信息 * @param c * @return */ public static void setDeviceInfo(Context c,RequestParams params){ ...

  5. 微信小程序 --- 获取设备信息

    获取设备信息: wx.getSystemInfo model:手机型号 pixelRatio:设备像素比 windowWidth:窗口宽度 windowHeight:窗口高度 language:语言 ...

  6. PhoneGap获取设备信息

    一. 获取设备信息的方法列表(如果没有或者检测不出来就显示undefined) 1.device.name              设备名称(一些国产机检测不出来) 2.device.model   ...

  7. appium自动化测试框架——封装获取设备信息类

    在上一节中,我们已经解决了如何在python中执行cmd,并获取执行结果.下面就小小实战一下,获取设备信息. 一.思路 1.windows上获取设备信息的方法 输入dos命令“adb devices” ...

  8. 小白学phoneGap《构建跨平台APP:phoneGap移动应用实战》连载五(使用PhoneGap获取设备信息)

    除了能够将HTML页面打包成可以直接安装运行的APP外,PhoneGap的一个最大优势在于可以通过JavaScript调用设备来访问设备上的硬件信息,从而实现一些原本只有依靠原生SDK才能够达到的目的 ...

  9. 微信小程序把玩(三十八)获取设备信息 API

    原文:微信小程序把玩(三十八)获取设备信息 API 获取设备信息这里分为四种, 主要属性: 网络信息wx.getNetWorkType, 系统信息wx.getSystemInfo, 重力感应数据wx. ...

随机推荐

  1. 通过Visualizing Representations来理解Deep Learning、Neural network、以及输入样本自身的高维空间结构

    catalogue . 引言 . Neural Networks Transform Space - 神经网络内部的空间结构 . Understand the data itself by visua ...

  2. Python Pandas 简单使用之 API熟悉

    1.read_csv li_index = ['round_id', 'index', 'c-sequen' ] dataset = pd.read_csv(file, low_memory=Fals ...

  3. SSH框架之hibernate《二》

    Hibernate第二天     一.hibernate的持久化类和对象标识符         1.1持久化类的编写规范             1.1.1什么是持久化类:               ...

  4. Oracle10gXE和Oracle SQL Developer本地安装配置

    第1部分 Oracle10gXE安装 Oracle10gXE安装的安装几乎是一路next就可以安装好:但是中间设置的用户名.密码.口令.SID等信息一定记住,后面需要使用. 第2部分 Oracle S ...

  5. EffectiveC++ 第6章 继承与面向对象设计

    我根据自己的理解,对原文的精华部分进行了提炼,并在一些难以理解的地方加上了自己的"可能比较准确"的「翻译」. Chapter 6 继承与面向对象设计 Inheritance and ...

  6. 分别基于TensorFlow、PyTorch、Keras的深度学习动手练习项目

    ×下面资源个人全都跑了一遍,不会出现仅是字符而无法运行的状况,运行环境: Geoffrey Hinton在多次访谈中讲到深度学习研究人员不要仅仅只停留在理论上,要多编程.个人在学习中也体会到单单的看理 ...

  7. Java中谈尾递归--尾递归和垃圾回收的比较

    一.首先我们讲讲递归 1.递归的本质是,某个方法中调用了自身,本质还是调用了一个方法,只是这个方法正好是自身而已 2.递归因为是在自身中调用自身,所以会带来以下三个显著特点:    1.调用的是同一个 ...

  8. (四)Java工程化--Git基础

    GIT学习参考:https://git-scm.com/book/zh/v2 常见命令 git init 初始化项目 git add *.java 添加文件到git版本控制(.java后缀的全部文件) ...

  9. Error while Installing APKs

    这一篇帖子 会写的比较简单 不过相信大家也可能遇到这些问题   为了怕自己忘记  记录下来  顺便也和大家一起分享 描述:在一些机型上安装软件 提示卸载原先的软件  但是又安装不上新软件DELETE_ ...

  10. nginx——location匹配流程图

    location匹配流程图 location理解 1.收到url请求后,nginx首先进行精确匹配(有“=”的为精确匹配),如果匹配成功,则直接返回精确匹配结果,如果没有命中则会继续向下进行普通匹配 ...