UNPKG

47 kBMarkdownView Raw
1<!-- markdownlint-disable MD024 MD034 MD033 -->
2
3# react-native-device-info
4
5[![npm version](https://badge.fury.io/js/react-native-device-info.svg)](http://badge.fury.io/js/react-native-device-info)
6[![npm total downloads](https://img.shields.io/npm/dt/react-native-device-info.svg)](https://img.shields.io/npm/dt/react-native-device-info.svg)
7[![npm monthly downloads](https://img.shields.io/npm/dm/react-native-device-info.svg)](https://img.shields.io/npm/dm/react-native-device-info.svg)
8[![npm weekly downloads](https://img.shields.io/npm/dw/react-native-device-info.svg)](https://img.shields.io/npm/dw/react-native-device-info.svg)
9
10Device Information for [React Native](https://github.com/facebook/react-native).
11
12## TOC
13
14- [Installation](#installation)
15- [Linking](#linking)
16- [Usage](#usage)
17- [API](#api)
18- [Troubleshooting](#troubleshooting)
19- [Release Notes](#release-notes)
20- [react-native-dom / react-native-web](#react-native-dom)
21
22## v6 to v7 upgrade
23
24Your iOS Podfile will need to move to an iOS 10 minimum. v7 of this module no longer supports iOS9.
25
26## Installation
27
28Using npm:
29
30```shell
31npm install --save react-native-device-info
32```
33
34or using yarn:
35
36```shell
37yarn add react-native-device-info
38```
39
40## Proguard
41
42If you want to use Install Referrer tracking, you will need to add this config to your Proguard config
43
44```
45-keepclassmembers class com.android.installreferrer.api.** {
46 *;
47}
48```
49
50If you are experiencing issues with hasGms() on your release apks, please add the following rule to your Proguard config
51```
52-keep class com.google.android.gms.common.** {*;}
53```
54
55## AndroidX Support
56
57This module defaults to AndroidX you should configure your library versions similar to this in your `android/build.gradle` file's "ext" block
58
59<details>
60 <summary>Android</summary>
61
62```gradle
63...
64 ext {
65 // dependency versions
66
67 We have 3 options for deviceId:
68 //Option 1 (latest):
69 firebaseIidVersion = "19.0.1" // default: "19.0.1"
70 //Option 2 (legacy GooglePlay dependency but using AndroidX):
71 googlePlayServicesIidVersion = "17.0.0" // default: "17.0.0" - AndroidX
72 //Option 3 (legacy GooglePlay dependency before AndroidX):
73 googlePlayServicesIidVersion = "16.0.1"
74
75
76 //include as needed:
77 compileSdkVersion = "28" // default: 28 (28 is required for AndroidX)
78 targetSdkVersion = "28" // default: 28 (28 is required for AndroidX)
79 supportLibVersion = '1.0.2' // Use '28.0.0' or don't specify for old libraries, '1.0.2' or similar for AndroidX
80 mediaCompatVersion = '1.0.1' // Do not specify if using old libraries, specify '1.0.1' or similar for androidx.media:media dependency
81 supportV4Version = '1.0.0' // Do not specify if using old libraries, specify '1.0.0' or similar for androidx.legacy:legacy-support-v4 dependency
82 }
83...
84```
85
86</details>
87
88If you need non-AndroidX you will need to use the jetifier package in reverse mode, documentation available with that package.
89
90## Linking
91
92Linking in native modules is a frequent source of trouble for new react-native developers, resulting in errors like "RNDeviceInfo is null" etc. For this reason automatic linking was implemented, and it should be used in your project.
93
94Automatic linking is supported for all platforms (even windows on React native >= 0.63!)
95
96Previous versions need to do manual linking. No support is offered for these previous react-native versions but you may refer to older versions of this README if you like. _Upgrade to modern versions of react-native. Use `upgrade-helper` tool on the internet if needed._
97
98## Usage
99
100```js
101import DeviceInfo from 'react-native-device-info';
102
103// or ES6+ destructured imports
104
105import { getUniqueId, getManufacturer } from 'react-native-device-info';
106```
107
108## API
109
110Note that many APIs are platform-specific. If there is no implementation for a platform, then the "default" return values you will receive are `"unknown"` for string, `-1` for number, and `false` for boolean. Arrays and Objects will be empty (`[]` and `{}` respectively).
111
112Most APIs return a Promise but also have a corresponding API with `Sync` on the end that operates synchronously. For example, you may prefer to call `isCameraPresentSync()` during your app bootstrap to avoid async calls during the first parts of app startup.
113
114The example app in this repository shows an example usage of every single API, consult the example app if you have questions, and if you think you see a problem make sure you can reproduce it using the example app before reporting it, thank you.
115
116| Method | Return Type | iOS | Android | Windows | Web |
117| ----------------------------------------------------------------- | ------------------- | :--: | :-----: | :-----: | :-: |
118| [getAndroidId()](#getandroidid) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ |
119| [getApiLevel()](#getapilevel) | `Promise<number>` | ❌ | ✅ | ❌ | ❌ |
120| [getApplicationName()](#getapplicationname) | `string` | ✅ | ✅ | ✅ | ❌ |
121| [getAvailableLocationProviders()](#getAvailableLocationProviders) | `Promise<Object>` | ✅ | ✅ | ❌ | ❌ |
122| [getBaseOs()](#getbaseOs) | `Promise<string>` | ❌ | ✅ | ✅ | ✅ |
123| [getBuildId()](#getbuildid) | `Promise<string>` | ✅ | ✅ | ✅ | ❌ |
124| [getBatteryLevel()](#getbatterylevel) | `Promise<number>` | ✅ | ✅ | ✅ | ✅ |
125| [getBootloader()](#getbootloader) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ |
126| [getBrand()](#getbrand) | `string` | ✅ | ✅ | ✅ | ❌ |
127| [getBuildNumber()](#getbuildnumber) | `string` | ✅ | ✅ | ✅ | ❌ |
128| [getBundleId()](#getbundleid) | `string` | ✅ | ✅ | ✅ | ❌ |
129| [isCameraPresent()](#iscamerapresent) | `Promise<boolean>` | ❌ | ✅ | ✅ | ✅ |
130| [getCarrier()](#getcarrier) | `Promise<string>` | ✅ | ✅ | ❌ | ❌ |
131| [getCodename()](#getcodename) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ |
132| [getDevice()](#getdevice) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ |
133| [getDeviceId()](#getdeviceid) | `string` | ✅ | ✅ | ✅ | ❌ |
134| [getDeviceType()](#getDeviceType) | `string` | ✅ | ✅ | ❌ | ❌ |
135| [getDisplay()](#getdisplay) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ |
136| [getDeviceName()](#getdevicename) | `Promise<string>` | ✅ | ✅ | ✅ | ❌ |
137| [getDeviceToken()](#getdevicetoken) | `Promise<string>` | ✅ | ❌ | ❌ | ❌ |
138| [getFirstInstallTime()](#getfirstinstalltime) | `Promise<number>` | ❌ | ✅ | ✅ | ❌ |
139| [getFingerprint()](#getfingerprint) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ |
140| [getFontScale()](#getfontscale) | `Promise<number>` | ✅ | ✅ | ✅ | ❌ |
141| [getFreeDiskStorage()](#getfreediskstorage) | `Promise<number>` | ✅ | ✅ | ✅ | ✅ |
142| [getFreeDiskStorageOld()](#getfreediskstorageold) | `Promise<number>` | ✅ | ✅ | ✅ | ✅ |
143| [getHardware()](#gethardware) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ |
144| [getHost()](#gethost) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ |
145| [getIpAddress()](#getipaddress) | `Promise<string>` | ✅ | ✅ | ✅ | ❌ |
146| [getIncremental()](#getincremental) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ |
147| [getInstallerPackageName()](#getinstallerpackagename) | `Promise<string>` | ✅ | ✅ | ✅ | ❌ |
148| [getInstallReferrer()](#getinstallreferrer) | `Promise<string>` | ❌ | ✅ | ✅ | ✅ |
149| [getInstanceId()](#getinstanceid) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ |
150| [getLastUpdateTime()](#getlastupdatetime) | `Promise<number>` | ❌ | ✅ | ❌ | ❌ |
151| [getMacAddress()](#getmacaddress) | `Promise<string>` | ✅ | ✅ | ❌ | ❌ |
152| [getManufacturer()](#getmanufacturer) | `Promise<string>` | ✅ | ✅ | ✅ | ❌ |
153| [getMaxMemory()](#getmaxmemory) | `Promise<number>` | ❌ | ✅ | ✅ | ✅ |
154| [getModel()](#getmodel) | `string` | ✅ | ✅ | ✅ | ❌ |
155| [getPhoneNumber()](#getphonenumber) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ |
156| [getPowerState()](#getpowerstate) | `Promise<object>` | ✅ | ✅ | ✅ | ✅ |
157| [getProduct()](#getproduct) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ |
158| [getPreviewSdkInt()](#getPreviewSdkInt) | `Promise<number>` | ❌ | ✅ | ❌ | ❌ |
159| [getReadableVersion()](#getreadableversion) | `string` | ✅ | ✅ | ✅ | ❌ |
160| [getSerialNumber()](#getserialnumber) | `Promise<string>` | ❌ | ✅ | ✅ | ❌ |
161| [getSecurityPatch()](#getsecuritypatch) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ |
162| [getSystemAvailableFeatures()](#getSystemAvailableFeatures) | `Promise<string[]>` | ❌ | ✅ | ❌ | ❌ |
163| [getSystemName()](#getsystemname) | `string` | ✅ | ✅ | ✅ | ❌ |
164| [getSystemVersion()](#getsystemversion) | `string` | ✅ | ✅ | ✅ | ❌ |
165| [getTags()](#gettags) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ |
166| [getType()](#gettype) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ |
167| [getTotalDiskCapacity()](#gettotaldiskcapacity) | `Promise<number>` | ✅ | ✅ | ✅ | ✅ |
168| [getTotalDiskCapacityOld()](#gettotaldiskcapacityold) | `Promise<number>` | ✅ | ✅ | ✅ | ✅ |
169| [getTotalMemory()](#gettotalmemory) | `Promise<number>` | ✅ | ✅ | ❌ | ✅ |
170| [getUniqueId()](#getuniqueid) | `string` | ✅ | ✅ | ✅ | ❌ |
171| [getUsedMemory()](#getusedmemory) | `Promise<number>` | ✅ | ✅ | ✅ | ✅ |
172| [getUserAgent()](#getuseragent) | `Promise<string>` | ✅ | ✅ | ❌ | ✅ |
173| [getVersion()](#getversion) | `string` | ✅ | ✅ | ✅ | ❌ |
174| [hasGms()](#hasGms) | `Promise<boolean>` | ❌ | ✅ | ❌ | ❌ |
175| [hasHms()](#hasHms) | `Promise<boolean>` | ❌ | ✅ | ❌ | ❌ |
176| [hasNotch()](#hasNotch) | `boolean` | ✅ | ✅ | ✅ | ❌ |
177| [hasSystemFeature()](#hassystemfeaturefeature) | `Promise<boolean>` | ❌ | ✅ | ❌ | ❌ |
178| [isAirplaneMode()](#isairplanemode) | `Promise<boolean>` | ❌ | ✅ | ❌ | ✅ |
179| [isBatteryCharging()](#isbatterycharging) | `Promise<boolean>` | ✅ | ✅ | ✅ | ✅ |
180| [isEmulator()](#isemulator) | `Promise<boolean>` | ✅ | ✅ | ✅ | ❌ |
181| [isKeyboardConnected()](#iskeyboardconnected) | `Promise<bool>` | ❌ | ❌ | ✅ | ❌ |
182| [isLandscape()](#isLandscape) | `Promise<boolean>` | ✅ | ✅ | ✅ | ❌ |
183| [isLocationEnabled()](#isLocationEnabled) | `Promise<boolean>` | ✅ | ✅ | ❌ | ✅ |
184| [isMouseConnected()](#ismouseconneted) | `Promise<bool>` | ❌ | ❌ | ✅ | ❌ |
185| [isHeadphonesConnected()](#isHeadphonesConnected) | `Promise<boolean>` | ✅ | ✅ | ❌ | ❌ |
186| [isPinOrFingerprintSet()](#ispinorfingerprintset) | `Promise<boolean>` | ✅ | ✅ | ✅ | ❌ |
187| [isTablet()](#istablet) | `boolean` | ✅ | ✅ | ✅ | ❌ |
188| [isTabletMode()](#istabletmode) | `Promise<bool>` | ❌ | ❌ | ✅ | ❌ |
189| [supported32BitAbis()](#supported32BitAbis) | `Promise<string[]>` | ❌ | ✅ | ❌ | ❌ |
190| [supported64BitAbis()](#supported64BitAbis) | `Promise<string[]>` | ❌ | ✅ | ❌ | ❌ |
191| [supportedAbis()](#supportedAbis) | `Promise<string[]>` | ✅ | ✅ | ❌ | ❌ |
192| [syncUniqueId()](#syncuniqueid) | `Promise<string>` | ✅ | ❌ | ❌ | ❌ |
193
194---
195
196### getApiLevel()
197
198Gets the API level.
199
200#### Examples
201
202```js
203DeviceInfo.getApiLevel().then((apiLevel) => {
204 // iOS: ?
205 // Android: 25
206 // Windows: ?
207});
208```
209
210#### Notes
211
212> See [API Levels](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)
213
214---
215
216### getAndroidId()
217
218Gets the ANDROID_ID. See [API documentation](https://developer.android.com/reference/android/provider/Settings.Secure#ANDROID_ID) for appropriate use.
219
220#### Examples
221
222```js
223DeviceInfo.getAndroidId().then((androidId) => {
224 // androidId here
225});
226```
227
228---
229
230### getApplicationName()
231
232Gets the application name.
233
234#### Examples
235
236```js
237let appName = DeviceInfo.getApplicationName();
238// AwesomeApp
239```
240
241---
242
243### getBaseOs()
244
245The base OS build the product is based on.
246
247#### Examples
248
249```js
250DeviceInfo.getBaseOs().then((baseOs) => {
251 // "Windows", "Android" etc
252});
253```
254
255---
256
257### getBatteryLevel()
258
259Gets the battery level of the device as a float comprised between 0 and 1.
260
261#### Examples
262
263```js
264DeviceInfo.getBatteryLevel().then((batteryLevel) => {
265 // 0.759999
266});
267```
268
269#### Notes
270
271> To be able to get actual battery level enable battery monitoring mode for application.
272> Add this code:
273
274```objective-c
275[UIDevice currentDevice].batteryMonitoringEnabled = true;
276```
277
278> to AppDelegate.m application:didFinishLaunchingWithOptions:
279>
280> Returns -1 on the iOS Simulator
281
282---
283
284### getBootloader()
285
286The system bootloader version number.
287
288#### Examples
289
290```js
291DeviceInfo.getBootloader().then((bootloader) => {
292 // "mw8998-002.0069.00"
293});
294```
295
296---
297
298### getBrand()
299
300Gets the device brand.
301
302#### Examples
303
304```js
305let brand = DeviceInfo.getBrand();
306// iOS: "Apple"
307// Android: "xiaomi"
308// Windows: ?
309```
310
311---
312
313### getBuildNumber()
314
315Gets the application build number.
316
317#### Examples
318
319```js
320let buildNumber = DeviceInfo.getBuildNumber();
321// iOS: "89"
322// Android: "4"
323// Windows: ?
324```
325
326---
327
328### getBundleId()
329
330Gets the application bundle identifier.
331
332#### Examples
333
334```js
335let bundleId = DeviceInfo.getBundleId();
336// "com.example.AwesomeApp"
337```
338
339---
340
341### isCameraPresent()
342
343Tells if the device has any camera now.
344
345#### Examples
346
347```js
348DeviceInfo.isCameraPresent()
349 .then((isCameraPresent) => {
350 // true or false
351 })
352 .catch((cameraAccessException) => {
353 // is thrown if a camera device could not be queried or opened by the CameraManager on Android
354 });
355```
356
357#### Notes
358
359> - Hot add/remove of camera is supported.
360> - Returns the status of the physical presence of the camera. If camera present but your app don't have permissions to use it, isCameraPresent will still return the true
361
362---
363
364### getCarrier()
365
366Gets the carrier name (network operator).
367
368#### Examples
369
370```js
371DeviceInfo.getCarrier().then((carrier) => {
372 // "SOFTBANK"
373});
374```
375
376---
377
378### getCodename()
379
380The current development codename, or the string "REL" if this is a release build.
381
382#### Examples
383
384```js
385DeviceInfo.getCodename().then((codename) => {
386 // "REL"
387});
388```
389
390---
391
392### getDevice()
393
394The name of the industrial design.
395
396#### Examples
397
398```js
399DeviceInfo.getDevice().then((device) => {
400 // "walleye"
401});
402```
403
404---
405
406### getDeviceId()
407
408Gets the device ID.
409
410#### Examples
411
412```js
413let deviceId = DeviceInfo.getDeviceId();
414// iOS: "iPhone7,2"
415// Android: "goldfish"
416// Windows: "Y3R94UC#AC4"
417```
418
419---
420
421### getDisplay()
422
423A build ID string meant for displaying to the user.
424
425#### Examples
426
427```js
428DeviceInfo.getDisplay().then((display) => {
429 // "OPM2.171026.006.G1"
430});
431```
432
433---
434
435### getDeviceName()
436
437Gets the device name.
438
439#### Examples
440
441```js
442DeviceInfo.getDeviceName().then((deviceName) => {
443 // iOS: "Becca's iPhone 6"
444 // Android: ?
445 // Windows: ?
446});
447```
448
449This used to require the android.permission.BLUETOOTH but the new implementation in v3 does not need it. You may remove that from your AndroidManifest.xml if you had it for this API.
450
451---
452
453### getDeviceToken()
454
455Gets the device token (see [DeviceCheck](https://developer.apple.com/documentation/devicecheck)). Only available for iOS 11.0+ on real devices.
456This will reject the promise when getDeviceToken is not supported, be careful with exception handling.
457
458#### Examples
459
460```js
461DeviceInfo.getDeviceToken().then((deviceToken) => {
462 // iOS: "a2Jqsd0kanz..."
463});
464```
465
466---
467
468### getFirstInstallTime()
469
470Gets the time at which the app was first installed, in milliseconds.
471
472#### Examples
473
474```js
475DeviceInfo.getFirstInstallTime().then((firstInstallTime) => {
476 // Android: 1517681764528
477});
478```
479
480---
481
482### getFingerprint()
483
484A string that uniquely identifies this build.
485
486#### Examples
487
488```js
489DeviceInfo.getFingerprint().then((fingerprint) => {
490 // "google/walleye/walleye:8.1.0/OPM2.171026.006.G1/4820017:user/release-keys"
491});
492```
493
494---
495
496### getFontScale()
497
498Gets the device font scale.
499The font scale is the ratio of the current system font to the "normal" font size, so if normal text is 10pt and the system font is currently 15pt, the font scale would be 1.5
500This can be used to determine if accessability settings has been changed for the device; you may want to re-layout certain views if the font scale is significantly larger ( > 2.0 )
501
502#### Examples
503
504```js
505DeviceInfo.getFontScale().then((fontScale) => {
506 // 1.2
507});
508```
509
510---
511
512### getFreeDiskStorage()
513
514Method that gets available storage size, in bytes, taking into account both root and data file systems calculation.
515
516#### Examples
517
518```js
519DeviceInfo.getFreeDiskStorage().then((freeDiskStorage) => {
520 // Android: 17179869184
521 // iOS: 17179869184
522});
523```
524
525#### Notes
526
527The API used by this method for Android was changed in [v6.0.0](https://github.com/react-native-community/react-native-device-info/releases/tag/v6.0.0). The older version has been maintained below as `getFreeDiskStorageOld()`. On iOS, `getFreeDiskStorage()` and `getFreeDiskStorageOld()` return the same value.
528
529---
530
531### getFreeDiskStorageOld()
532
533Old implementation of method that gets available storage size, in bytes.
534
535#### Examples
536
537```js
538DeviceInfo.getFreeDiskStorageOld().then((freeDiskStorage) => {
539 // Android: 17179869184
540 // iOS: 17179869184
541});
542```
543
544#### Notes
545
546> From [developer.android.com](<https://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()>):
547>
548> This method was deprecated in API level 29.
549>
550> Return the primary shared/external storage directory.
551>
552> Note: don't be confused by the word "external" here. This directory can better be thought as
553> media/shared storage. It is a filesystem that can hold a relatively large amount of data and
554> that is shared across all applications (does not enforce permissions). Traditionally this is
555> an SD card, but it may also be implemented as built-in storage in a device that is distinct
556> from the protected internal storage and can be mounted as a filesystem on a computer.
557
558---
559
560### getHardware()
561
562The name of the hardware (from the kernel command line or /proc).
563
564#### Examples
565
566```js
567DeviceInfo.getHardware().then(hardware => {
568 // "walleye"
569};
570```
571
572---
573
574### getHost()
575
576Hostname
577
578#### Examples
579
580```js
581DeviceInfo.getHost().then((host) => {
582 // "wprd10.hot.corp.google.com"
583});
584```
585
586---
587
588### getIpAddress()
589
590**Deprecated** Gets the device current IP address. (of wifi only)
591Switch to [react-native-netinfo/netinfo](https://github.com/react-native-netinfo/react-native-netinfo) or [react-native-network-info](https://github.com/pusherman/react-native-network-info)
592
593#### Examples
594
595```js
596DeviceInfo.getIpAddress().then((ip) => {
597 // "92.168.32.44"
598});
599```
600
601#### Android Permissions
602
603- [android.permission.ACCESS_WIFI_STATE](https://developer.android.com/reference/android/Manifest.permission.html#ACCESS_WIFI_STATE)
604
605#### Notes
606
607> Support for iOS was added in 0.22.0
608
609---
610
611### getIncremental()
612
613The internal value used by the underlying source control to represent this build.
614
615#### Examples
616
617```js
618DeviceInfo.getIncremental().then((incremental) => {
619 // "4820017"
620});
621```
622
623---
624
625### getInstallerPackageName()
626
627The internal value used by the underlying source control to represent this build.
628
629#### Examples
630
631```js
632DeviceInfo.getInstallerPackageName().then((installerPackageName) => {
633 // Play Store: "com.android.vending"
634 // Amazon: "com.amazon.venezia"
635 // Samsung App Store: "com.sec.android.app.samsungapps"
636 // iOS: "AppStore", "TestFlight", "Other"
637});
638```
639
640---
641
642### getInstallReferrer()
643
644Gets the referrer string upon application installation.
645
646#### Examples
647
648```js
649DeviceInfo.getInstallReferrer().then((installReferrer) => {
650 // If the app was installed from https://play.google.com/store/apps/details?id=com.myapp&referrer=my_install_referrer
651 // the result will be "my_install_referrer"
652});
653```
654
655---
656
657### getInstanceId()
658
659Gets the application instance ID.
660
661#### Examples
662
663```js
664DeviceInfo.getInstanceId().then((instanceId) => {
665 // Android: ?
666});
667```
668
669#### Notes
670
671> See https://developers.google.com/instance-id/
672
673---
674
675### getLastUpdateTime()
676
677Gets the time at which the app was last updated, in milliseconds.
678
679#### Examples
680
681```js
682DeviceInfo.getLastUpdateTime().then((lastUpdateTime) => {
683 // Android: 1517681764992
684});
685```
686
687---
688
689### getMacAddress()
690
691Gets the network adapter MAC address.
692
693#### Examples
694
695```js
696DeviceInfo.getMacAddress().then((mac) => {
697 // "E5:12:D8:E5:69:97"
698});
699```
700
701#### Android Permissions
702
703- [android.permission.ACCESS_WIFI_STATE](https://developer.android.com/reference/android/Manifest.permission.html#ACCESS_WIFI_STATE)
704
705#### Notes
706
707> iOS: This method always return "02:00:00:00:00:00" as retrieving the MAC address is [disabled since iOS 7](https://developer.apple.com/library/archive/releasenotes/General/WhatsNewIniOS/Articles/iOS7.html#//apple_ref/doc/uid/TP40013162-SW34)
708
709---
710
711### getManufacturer()
712
713Gets the device manufacturer.
714
715#### Examples
716
717```js
718DeviceInfo.getManufacturer().then((manufacturer) => {
719 // iOS: "Apple"
720 // Android: "Google"
721 // Windows: ?
722});
723```
724
725---
726
727### getMaxMemory()
728
729Returns the maximum amount of memory that the VM will attempt to use, in bytes.
730
731#### Examples
732
733```js
734DeviceInfo.getMaxMemory().then((maxMemory) => {
735 // 402653183
736});
737```
738
739---
740
741### getModel()
742
743Gets the device model.
744
745**iOS warning:** The list with device names is maintained by the community and could lag new devices. It is recommended to use `getDeviceId()` since it's more reliable and always up-to-date with new iOS devices. We do accept pull requests that add new iOS devices to the list with device names.
746
747#### Examples
748
749```js
750let model = DeviceInfo.getModel();
751// iOS: ?
752// Android: ?
753// Windows: ?
754```
755
756---
757
758### getPhoneNumber()
759
760Gets the device phone number.
761
762#### Examples
763
764```js
765DeviceInfo.getPhoneNumber().then((phoneNumber) => {
766 // Android: null return: no permission, empty string: unprogrammed or empty SIM1, e.g. "+15555215558": normal return value
767});
768```
769
770#### Android Permissions
771
772- [android.permission.READ_PHONE_STATE](https://developer.android.com/reference/android/Manifest.permission.html#READ_PHONE_STATE)
773
774#### Notes
775
776> This can return `undefined` in certain cases and should not be relied on. [SO entry on the subject](https://stackoverflow.com/questions/2480288/programmatically-obtain-the-phone-number-of-the-android-phone#answer-2480307).
777
778---
779
780### getPowerState()
781
782Gets the power state of the device including the battery level, whether it is plugged in, and if the system is currently operating in low power mode.
783Displays a warning on iOS if battery monitoring not enabled, or if attempted on an emulator (where monitoring is not possible)
784
785#### Examples
786
787```js
788DeviceInfo.getPowerState().then((state) => {
789 // {
790 // batteryLevel: 0.759999,
791 // batteryState: 'unplugged',
792 // lowPowerMode: false,
793 // }
794});
795```
796
797---
798
799### getProduct()
800
801The name of the overall product.
802
803#### Examples
804
805```js
806DeviceInfo.getProduct().then((product) => {
807 // "walleye"
808});
809```
810
811---
812
813### getPreviewSdkInt()
814
815The developer preview revision of a prerelease SDK.
816
817#### Examples
818
819```js
820DeviceInfo.getPreviewSdkInt().then((previewSdkInt) => {
821 // 0
822});
823```
824
825---
826
827### getReadableVersion()
828
829Gets the application human readable version (same as getVersion() + '.' + getBuildNumber())
830
831#### Examples
832
833```js
834let readableVersion = DeviceInfo.getReadableVersion();
835// iOS: 1.0.1.32
836// Android: 1.0.1.234
837// Windows: ?
838```
839
840---
841
842### getSerialNumber()
843
844Gets the device serial number. Will be 'unknown' in almost all cases [unless you have a privileged app and you know what you're doing](<https://developer.android.com/reference/android/os/Build.html#getSerial()>).
845
846#### Examples
847
848```js
849DeviceInfo.getSerialNumber().then((serialNumber) => {
850 // iOS: unknown
851 // Android: ? (maybe a serial number, if your app is privileged)
852 // Windows: ? (a serial number, if your app has the "capability smbios")
853});
854```
855## Notes
856### capability smbios
857If you want to use this method in windows, you have to add smbios capability in your aplication. Please following this [documentation](https://docs.microsoft.com/en-us/windows/win32/sysinfo/access-smbios-information-from-a-universal-windows-app) for add the capability in your manifest file.
858
859---
860
861### getSecurityPatch()
862
863The user-visible security patch level.
864
865#### Examples
866
867```js
868DeviceInfo.getSecurityPatch().then((securityPatch) => {
869 // "2018-07-05"
870});
871```
872
873---
874
875### getSystemName()
876
877Gets the device OS name.
878
879#### Examples
880
881```js
882let systemName = DeviceInfo.getSystemName();
883// iOS: "iOS" on newer iOS devices "iPhone OS" on older devices, including older iPad's.
884// Android: "Android"
885// Windows: ?
886```
887
888---
889
890### getSystemVersion()
891
892Gets the device OS version.
893
894#### Examples
895
896```js
897let systemVersion = DeviceInfo.getSystemVersion();
898// iOS: "11.0"
899// Android: "7.1.1"
900// Windows: ?
901```
902
903---
904
905### getBuildId()
906
907Gets build number of the operating system.
908
909#### Examples
910
911```js
912DeviceInfo.getBuildId().then((buildId) => {
913 // iOS: "12A269"
914 // tvOS: not available
915 // Android: "13D15"
916 // Windows: not available
917});
918```
919
920---
921
922### getTags()
923
924Comma-separated tags describing the build.
925
926#### Examples
927
928```js
929DeviceInfo.getTags().then((tags) => {
930 // "release-keys, unsigned, debug",
931});
932```
933
934---
935
936### getType()
937
938The type of build.
939
940#### Examples
941
942```js
943DeviceInfo.getType().then((type) => {
944 // "user", "eng"
945});
946```
947
948---
949
950### getTotalDiskCapacity()
951
952Method that gets full disk storage size, in bytes, taking into account both root and data file systems calculation.
953
954#### Examples
955
956```js
957DeviceInfo.getTotalDiskCapacity().then((capacity) => {
958 // Android: 17179869184
959 // iOS: 17179869184
960});
961```
962
963#### Notes
964
965The API used by this method for Android was changed in [v6.0.0](https://github.com/react-native-community/react-native-device-info/releases/tag/v6.0.0). The older version has been maintained below as `getTotalDiskCapacityOld()`. On iOS, `getTotalDiskCapacity()` and `getTotalDiskCapacityOld()` return the same value.
966
967---
968
969### getTotalDiskCapacityOld()
970
971Old implementation of method that gets full disk storage size, in bytes.
972
973#### Examples
974
975```js
976DeviceInfo.getTotalDiskCapacityOld().then((capacity) => {
977 // Android: 17179869184
978 // iOS: 17179869184
979});
980```
981
982---
983
984### getTotalMemory()
985
986Gets the device total memory, in bytes.
987
988#### Examples
989
990```js
991DeviceInfo.getTotalMemory().then((totalMemory) => {
992 // 1995018240
993});
994```
995
996---
997
998### getUniqueId()
999
1000This is a constant and may be referenced directly
1001
1002Gets the device unique ID.
1003On Android it is currently identical to `getAndroidId()` in this module.
1004On iOS it uses the `DeviceUID` uid identifier.
1005On Windows it uses `Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation.id`.
1006
1007#### Examples
1008
1009```js
1010let uniqueId = DeviceInfo.getUniqueId();
1011// iOS: "FCDBD8EF-62FC-4ECB-B2F5-92C9E79AC7F9"
1012// Android: "dd96dec43fb81c97"
1013// Windows: ?
1014```
1015
1016#### Notes
1017
1018> - iOS: This is [`IDFV`](https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor) or a random string if IDFV is unavaliable. Once UID is generated it is stored in iOS Keychain and NSUserDefaults. So it would stay the same even if you delete the app or reset IDFV. You can _carefully_ consider it a persistent, cross-install unique ID. It can be changed only in case someone manually override values in Keychain/NSUserDefaults or if Apple would change Keychain and NSUserDefaults implementations.
1019> Beware: The IDFV is calculated using your bundle identifier and thus will be different in app extensions.
1020> - android: Prior to Oreo, this id ([ANDROID_ID](https://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID)) will always be the same once you set up your phone.
1021
1022---
1023
1024### syncUniqueId()
1025
1026This method is intended for iOS.
1027
1028This synchronizes uniqueId with [`IDFV`](https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor) or sets new a random string.
1029
1030On iOS it uses the `DeviceUID` uid identifier.
1031On other platforms it just call `getUniqueId()` in this module.
1032
1033#### Examples
1034
1035```js
1036DeviceInfo.syncUniqueId().then((uniqueId) => {
1037 // iOS: "FCDBD8EF-62FC-4ECB-B2F5-92C9E79AC7F9"
1038 // Android: "dd96dec43fb81c97"
1039 // Windows: ?
1040});
1041```
1042
1043#### Notes
1044
1045> - If user moved or restored data from one iOS device to second iOS device then he will have two different devices with same `uniqueId` in Keychain/NSUserDefaults. User can call `syncUniqueId()` on new iOS device. That will update his `uniqueId` from [`IDFV`](https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor) or a random string.
1046
1047---
1048
1049### getUsedMemory()
1050
1051Gets the app memory usage, in bytes.
1052
1053⚠️ [A note from the Android docs.](https://developer.android.com/reference/android/app/ActivityManager#getProcessMemoryInfo(int%5B%5D))
1054> Note: this method is only intended for debugging or building a user-facing process management UI.
1055
1056#### Examples
1057
1058```js
1059DeviceInfo.getUsedMemory().then((usedMemory) => {
1060 // 23452345
1061});
1062```
1063
1064---
1065
1066### getUserAgent()
1067
1068Gets the device User Agent.
1069
1070#### Examples
1071
1072```js
1073DeviceInfo.getUserAgent().then((userAgent) => {
1074 // iOS: "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143"
1075 // tvOS: not available
1076 // Android: ?
1077 // Windows: ?
1078});
1079```
1080
1081---
1082
1083### getVersion()
1084
1085Gets the application version.
1086
1087#### Examples
1088
1089```js
1090let version = DeviceInfo.getVersion();
1091// iOS: "1.0"
1092// Android: "1.0"
1093// Windows: ?
1094```
1095
1096---
1097
1098### isAirplaneMode()
1099
1100Tells if the device is in Airplane Mode.
1101
1102#### Examples
1103
1104```js
1105DeviceInfo.isAirplaneMode().then((airplaneModeOn) => {
1106 // false
1107});
1108```
1109
1110#### Notes
1111
1112> - This only works if the remote debugger is disabled.
1113
1114---
1115
1116### isBatteryCharging()
1117
1118Tells if the battery is currently charging.
1119
1120#### Examples
1121
1122```js
1123DeviceInfo.isBatteryCharging().then((isCharging) => {
1124 // true or false
1125});
1126```
1127
1128---
1129
1130### isEmulator()
1131
1132Tells if the application is running in an emulator.
1133
1134#### Examples
1135
1136```js
1137DeviceInfo.isEmulator().then((isEmulator) => {
1138 // false
1139});
1140```
1141
1142---
1143
1144### isKeyboardConnected()
1145
1146Tells if the device has a keyboard connected.
1147
1148#### Examples
1149
1150```js
1151let isKeyboardConnected = DeviceInfo.isKeyboardConnected();
1152// true
1153```
1154
1155---
1156
1157### isPinOrFingerprintSet()
1158
1159Tells if a PIN number or a fingerprint was set for the device.
1160
1161#### Examples
1162
1163```js
1164DeviceInfo.isPinOrFingerprintSet().then((isPinOrFingerprintSet) => {
1165 if (!isPinOrFingerprintSet) {
1166 // ...
1167 }
1168});
1169```
1170
1171---
1172
1173### isTablet()
1174
1175Tells if the device is a tablet.
1176
1177#### Examples
1178
1179```js
1180let isTablet = DeviceInfo.isTablet();
1181// true
1182```
1183
1184---
1185
1186### isTabletMode()
1187
1188Tells if the device is in tablet mode.
1189
1190#### Examples
1191
1192```js
1193let isTabletMode = DeviceInfo.isTabletMode();
1194// true
1195```
1196
1197---
1198
1199### isLandscape()
1200
1201Tells if the device is currently in landscape mode.
1202
1203#### Examples
1204
1205```js
1206DeviceInfo.isLandscape().then((isLandscape) => {
1207 // true
1208});
1209```
1210
1211---
1212
1213### isMouseConnected()
1214
1215Tells if the device has a mouse connected.
1216
1217#### Examples
1218
1219```js
1220let isMouseConnected = DeviceInfo.isMouseConnected();
1221// true
1222```
1223
1224---
1225
1226### hasGms()
1227
1228Tells if the device supports Google Mobile Services.
1229
1230#### Examples
1231
1232```js
1233DeviceInfo.hasGms().then((hasGms) => {
1234 // true
1235});
1236```
1237
1238---
1239
1240### hasHms()
1241
1242Tells if the device supports Huawei Mobile Services.
1243
1244#### Examples
1245
1246```js
1247DeviceInfo.hasHms().then((hasHms) => {
1248 // true
1249});
1250```
1251
1252---
1253
1254### hasNotch()
1255
1256Tells if the device has a notch.
1257
1258#### Examples
1259
1260```js
1261let hasNotch = DeviceInfo.hasNotch();
1262// true
1263```
1264
1265---
1266
1267### getDeviceType()
1268
1269Returns the device's type as a string, which will be one of:
1270
1271- `Handset`
1272- `Tablet`
1273- `Tv`
1274- `Desktop`
1275- `GamingConsole`
1276- `unknown`
1277
1278#### Examples
1279
1280```js
1281let type = DeviceInfo.getDeviceType();
1282// 'Handset'
1283```
1284
1285---
1286
1287### supported32BitAbis()
1288
1289An ordered list of 32 bit ABIs supported by this device.
1290
1291#### Examples
1292
1293```js
1294DeviceInfo.supported32BitAbis().then((abis) => {
1295 // ["armeabi-v7a", "armeabi"]
1296});
1297```
1298
1299---
1300
1301### supported64BitAbis()
1302
1303An ordered list of 64 bit ABIs supported by this device.
1304
1305#### Examples
1306
1307```js
1308DeviceInfo.supported64BitAbis().then((abis) => {
1309 // ["arm64-v8a"]
1310});
1311```
1312
1313---
1314
1315### supportedAbis()
1316
1317Returns a list of supported processor architecture version
1318
1319#### Examples
1320
1321```js
1322DeviceInfo.supportedAbis().then((abis) => {
1323 // [ "arm64 v8", "Intel x86-64h Haswell", "arm64-v8a", "armeabi-v7a", "armeabi" ]
1324});
1325```
1326
1327---
1328
1329### hasSystemFeature(feature)
1330
1331Tells if the device has a specific system feature.
1332
1333#### Examples
1334
1335```js
1336DeviceInfo.hasSystemFeature('amazon.hardware.fire_tv').then((hasFeature) => {
1337 // true or false
1338});
1339```
1340
1341---
1342
1343### getSystemAvailableFeatures()
1344
1345Returns a list of available system features on Android.
1346
1347#### Examples
1348
1349```js
1350DeviceInfo.getSystemAvailableFeatures().then((features) => {
1351 // ["android.software.backup", "android.hardware.screen.landscape", "android.hardware.wifi", ...]
1352});
1353```
1354
1355### isLocationEnabled()
1356
1357Tells if the device has location services turned off at the device-level (NOT related to app-specific permissions)
1358
1359#### Examples
1360
1361```js
1362DeviceInfo.isLocationEnabled().then((enabled) => {
1363 // true or false
1364});
1365```
1366
1367### isHeadphonesConnected()
1368
1369Tells if the device is connected to wired headset or bluetooth headphones
1370
1371#### Examples
1372
1373```js
1374DeviceInfo.isHeadphonesConnected().then((enabled) => {
1375 // true or false
1376});
1377```
1378
1379### getAvailableLocationProviders()
1380
1381Returns an object of **platform-specfic** location providers/servcies, with `boolean` value whether or not they are currently available.
1382
1383> NOTE: This function requires access to the Location permission on Android
1384
1385#### Android Example
1386
1387```js
1388DeviceInfo.getAvailableLocationProviders().then((providers) => {
1389 // {
1390 // gps: true
1391 // network: true
1392 // passive: true
1393 // }
1394});
1395```
1396
1397#### iOS Example
1398
1399```js
1400DeviceInfo.getAvailableLocationProviders().then((providers) => {
1401 // {
1402 // headingAvailable: false
1403 // isRangingAvailable: false
1404 // locationServicesEnabled: true
1405 // significantLocationChangeMonitoringAvailable: true
1406 // }
1407});
1408```
1409
1410## Hooks & Events
1411
1412Currently iOS & Android only (web support for battery/charging-related APIs).
1413
1414### useBatteryLevel or RNDeviceInfo_batteryLevelDidChange
1415
1416Fired when the battery level changes; sent no more frequently than once per minute.
1417
1418#### Examples
1419
1420```js
1421import { useBatteryLevel } from 'react-native-device-info';
1422
1423const batteryLevel = useBatteryLevel(); // 0.759999
1424
1425<Text>{batteryLevel}</Text>;
1426```
1427
1428```js
1429import { NativeEventEmitter, NativeModules } from 'react-native';
1430const deviceInfoEmitter = new NativeEventEmitter(NativeModules.RNDeviceInfo);
1431
1432deviceInfoEmitter.addListener('RNDeviceInfo_batteryLevelDidChange', (level) => {
1433 // 0.759999
1434});
1435```
1436
1437---
1438
1439### useBatteryLevelIsLow or RNDeviceInfo_batteryLevelIsLow
1440
1441Fired when the battery drops is considered low
1442
1443| Platform | Percentage |
1444| -------- | ---------- |
1445| iOS | 20 |
1446| Android | 15 |
1447| Web | 20 |
1448
1449#### Examples
1450
1451```js
1452import { useBatteryLevelIsLow } from 'react-native-device-info';
1453
1454const batteryLevelIsLow = useBatteryLevelIsLow(); // 0.19
1455
1456<Text>{batteryLevelIsLow}</Text>;
1457```
1458
1459```js
1460import { NativeEventEmitter, NativeModules } from 'react-native';
1461const deviceInfoEmitter = new NativeEventEmitter(NativeModules.RNDeviceInfo);
1462
1463deviceInfoEmitter.addListener('RNDeviceInfo_batteryLevelIsLow', (level) => {
1464 // 0.19
1465});
1466```
1467
1468---
1469
1470### usePowerState or RNDeviceInfo_powerStateDidChange
1471
1472Fired when the battery state changes, for example when the device enters charging mode or is unplugged.
1473
1474#### Examples
1475
1476```js
1477import { usePowerState } from 'react-native-device-info';
1478
1479const powerState = usePowerState(); // 'charging'
1480
1481<Text>{powerState}</Text>;
1482```
1483
1484```js
1485import { NativeEventEmitter, NativeModules } from 'react-native'
1486const deviceInfoEmitter = new NativeEventEmitter(NativeModules.RNDeviceInfo)
1487
1488deviceInfoEmitter.addListener('RNDeviceInfo_powerStateDidChange', { batteryState } => {
1489 // 'charging'
1490});
1491```
1492
1493---
1494
1495### useFirstInstallTime
1496
1497Gets the time at which the app was first installed, in milliseconds.
1498
1499#### Example
1500
1501```jsx
1502import { useFirstInstallTime } from 'react-native-device-info';
1503
1504const { loading, result } = useFirstInstallTime(); // { loading: true, result: 1517681764528}
1505
1506<Text>{loading ? 'loading...' : result}</Text>;
1507```
1508
1509---
1510
1511### useDeviceName
1512
1513Gets the device name.
1514
1515#### Example
1516
1517```jsx
1518import { useDeviceName } from 'react-native-device-info';
1519
1520const { loading, result } = useDeviceName(); // { loading: true, result: "Becca's iPhone 6"}
1521
1522<Text>{loading ? 'loading...' : result}</Text>;
1523```
1524
1525---
1526
1527### useHasSystemFeature
1528
1529Tells if the device has a specific system feature.
1530
1531#### Example
1532
1533```jsx
1534import { useHasSystemFeature } from 'react-native-device-info';
1535
1536const { loading, result } = useHasSystemFeature('amazon.hardware.fire_tv'); // { loading: true, result: false }
1537
1538<Text>{loading ? 'loading...' : result}</Text>;
1539```
1540
1541---
1542
1543### useIsEmulator
1544
1545Get whether the application is running in an emulator.
1546
1547#### Example
1548
1549```jsx
1550import { useIsEmulator } from 'react-native-device-info';
1551
1552const { loading, result } = useIsEmulator(); // { loading: true, result: false }
1553
1554<Text>{loading ? 'loading...' : result}</Text>;
1555```
1556
1557---
1558
1559### useManufacturer
1560
1561Gets the device manufacturer.
1562
1563#### Example
1564
1565```jsx
1566import { useManufacturer } from 'react-native-device-info';
1567
1568const { loading, result } = useManufacturer(); // { loading: true, result: "Apple"}
1569
1570<Text>{loading ? 'loading...' : result}</Text>;
1571```
1572
1573---
1574
1575### useIsHeadphonesConnected
1576
1577Tells if the device is connected to wired headset or bluetooth headphones.
1578
1579This hook subscribes to the event, `RNDeviceInfo_headphoneConnectionDidChange` , and updates the `result` field accordingly.
1580
1581#### Example
1582
1583```jsx
1584import { useIsHeadphonesConnected } from 'react-native-device-info';
1585
1586const { loading, result } = useIsHeadphonesConnected(); // { loading: true, result: false}
1587
1588<Text>{loading ? 'loading...' : result}</Text>;
1589```
1590
1591=======
1592
1593## Native interoperatibily
1594
1595If you need to check for device type from the native side, you can use the following:
1596
1597```java
1598import com.learnium.resolver.DeviceTypeResolver
1599
1600...
1601deviceTypeResolver = new DeviceTypeResolver(context);
1602...
1603//Check if the device is a Tablet:
1604if(deviceTypeResolver.isTablet){
1605 ...
1606}else{
1607 ...
1608}
1609```
1610
1611## Troubleshooting
1612
1613When installing or using `react-native-device-info`, you may encounter the following problems:
1614
1615<details>
1616 <summary>[android] - Unable to merge dex / Multiple dex files / Problems with `com.google.android.gms`</summary>
1617
1618`react-native-device-info` uses `com.google.android.gms:play-services-gcm` to provide [getInstanceId()](#getinstanceid).
1619This can lead to conflicts when building the Android application.
1620
1621If you're using a different version of `com.google.android.gms:play-services-gcm` in your app, you can define the
1622`googlePlayServicesVersion` gradle variable in your `build.gradle` file to tell `react-native-device-info` what version
1623it should require. See the example project included here for a sample.
1624
1625If you're using a different library that conflicts with `com.google.android.gms:play-services-gcm`, and you are certain you know what you are doing such that you will avoid version conflicts, you can simply
1626ignore this dependency in your gradle file:
1627
1628```groovy
1629 compile(project(':react-native-device-info')) {
1630 exclude group: 'com.google.android.gms'
1631}
1632```
1633
1634</details>
1635
1636<details>
1637 <summary>[ios] - ld: library not found for -lRNDeviceInfo-tvOS</summary>
1638
1639Seems to be a bug caused by `react-native link`. You can manually delete `libRNDeviceInfo-tvOS.a` in `Xcode -> [Your iOS build target] -> Build Phrases -> Link Binary with Libraries`.
1640
1641</details>
1642
1643<details>
1644 <summary>[ios] - [NetworkInfo] Descriptors query returned error: Error Domain=NSCocoaErrorDomain Code=4099
1645 “The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated.”</summary>
1646
1647This is a system level log that may be turned off by executing:
1648`xcrun simctl spawn booted log config --mode "level:off" --subsystem com.apple.CoreTelephony`.
1649To undo the command, you can execute:
1650`xcrun simctl spawn booted log config --mode "level:info" --subsystem com.apple.CoreTelephony`
1651
1652</details>
1653
1654<details>
1655 <summary>[ios] - Multiple versions of React when using CocoaPods
1656 "tries to require 'react-native' but there are several files providing this module"</summary>
1657
1658### RN<=59 You may need to adjust your Podfile like this if you use Cocoapods and have undefined symbols or duplicate React definitions
1659
1660```ruby
1661target 'yourTargetName' do
1662 # See http://facebook.github.io/react-native/docs/integration-with-existing-apps.html#configuring-cocoapods-dependencies
1663 pod 'React', :path => '../node_modules/react-native', :subspecs => [
1664 'Core',
1665 'CxxBridge', # Include this for RN >= 0.47
1666 'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
1667 'RCTText',
1668 'RCTNetwork',
1669 'RCTWebSocket', # Needed for debugging
1670 'RCTAnimation', # Needed for FlatList and animations running on native UI thread
1671 # Add any other subspecs you want to use in your project
1672 ]
1673
1674 # Explicitly include Yoga if you are using RN >= 0.42.0
1675 pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
1676
1677 # Third party deps podspec link - you may have multiple pods here, just an example
1678 pod 'RNDeviceInfo', path: '../node_modules/react-native-device-info'
1679
1680end
1681
1682# if you see errors about React duplicate definitions, this fixes it. The same works for yoga.
1683post_install do |installer|
1684 installer.pods_project.targets.each do |target|
1685 if target.name == "React"
1686 target.remove_from_project
1687 end
1688 end
1689end
1690```
1691
1692</details>
1693
1694<details>
1695 <summary>[tests] - Cannot run my test suite when using this library</summary>
1696
1697`react-native-device-info` contains native code, and needs to be mocked. Jest Snapshot support may work though.
1698
1699If you do not have a Jest Setup file configured, you should add the following to your Jest settings and create the jest.setup.js file in project root:
1700
1701```js
1702setupFiles: ['<rootDir>/jest.setup.js'];
1703```
1704
1705You should then add the following to your Jest setup file to mock the DeviceInfo Native Module:
1706
1707```js
1708import mockRNDeviceInfo from 'react-native-device-info/jest/react-native-device-info-mock';
1709
1710jest.mock('react-native-device-info', () => mockRNDeviceInfo);
1711```
1712
1713Checkout the example project for more information.
1714
1715</details>
1716<details>
1717 <summary>[warnings] - I get too many warnings (battery state, etc)</summary>
1718
1719Some of the APIs (like getBatteryState) will throw warnings in certain conditions like on tvOS or the iOS emulator. This won't be visible in production but even in development it may be irritating. It is useful to have the warnings because these devices return no state, and that can be surprising, leading to github support issues. The warnings is intended to educate you as a developer. If the warnings are troublesome you may try this in your code to suppress them:
1720
1721```javascript
1722import { YellowBox } from 'react-native';
1723YellowBox.ignoreWarnings(['Battery state']);
1724```
1725
1726</details>
1727
1728## Release Notes
1729
1730See the [CHANGELOG.md](https://github.com/react-native-community/react-native-device-info/blob/master/CHANGELOG.md).
1731
1732## Contributing
1733
1734Please see the [`contributing guide`](/CONTRIBUTING.md).
1735
1736## react-native-dom
1737
1738As a courtesy to developers, this library was made compatible in v0.21.6 with [react-native-dom](https://github.com/vincentriemer/react-native-dom) and [react-native-web](https://github.com/necolas/react-native-web) by providing an empty polyfill in order to avoid breaking builds.
1739
1740Only [getUserAgent()](#getuseragent) will return a correct value. All other API methods will return an "empty" value of its documented return type: `0` for numbers, `''` for strings, `false` for booleans.