UNPKG

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