npm package: @pod-point/react-native-device-info
Description: Device information component for React Native
Author: Edward Coleridge Smith
Latest version: 1.0.2

# React Native Device Information Integration

This package provides device information for both Android and iOS devices. If you have push notifications enabled  then
this package can also provide the device token required to use this feature.

## Installation

```bash
npm install @pod-point/react-native-device-info --save
```

## iOS Setup Guide

 1. Open up your React Native project in XCode, this is the `.xcodeproj` file in the `ios` directory of your React
 Native project.
 2. Open `node_modules/@pod-point/react-native-device-info/ios` in Finder and locate the `PPTDeviceInfo.xcodeproj`
 package. Drag this file into the XCode project navigator. You can keep this in the `Libraries` group along with all the
 other React Native packages.
 3. Click on the root of your project in XCode, then select your project's main target. Click on *Build Phases* and
 double check that the `libPPTDeviceInfo.a` product was added. If not, expand the `Products` group in
 `PPTDeviceInfo.xcodeproj` and drag this file in.

### Optional Extras

If you're using push notifications then you'll need to get hold of the device token. This token isn't immediately
available to the app and extra configruation is required. If you need the device token, follow these steps:

 1. Click on the root of your project in XCode, then select your project's main target. Select *Build Settings* and then
 search for *Header Search Paths*. Add `$(SRCROOT)/../node_modules/@pod-point/react-native-device-info` to the header
 search path list and make sure that it is set to *recursive*.
 2. Ensure that your app delegate is correctly registering user notifications. You should have already completed this
 step if you're already using push notifications.
 3. In your `didRegisterForRemoteNotificationsWithDeviceToken` delegate, add the following line:
 `[PPTDeviceInfoProvider provideDeviceToken:[deviceToken description]];`. This assumes that your delegate has called
 the device token `NSObject` `deviceToken`.

## Android Setup Guide

 1. Open up your React Native project in Android Studio, this is the `android` directory in your React Native project.
 2. Expand *Gradle Scripts* from within the project tree and open `settings.gradle`. Replace the line in the script
 which states `include ':app'` with `include ':app', ':pptdeviceinfo'` (or append `':pptdeviceinfo'` to the end of the
 include statement if you're already including other modules).
 3. Add the following line to the end of `settings.gradle`:
 ```
 project(':pptdeviceinfo').projectDir = new File(rootProject.projectDir, '../node_modules/@pod-point/react-native-device-info/android/library')
 ```
 4. Open up your `app` module `build.gradle` file and add the following line to the end of your dependancies section:
 ```
 compile project(path: ':pptdeviceinfo')
 ```
 5. You should now be prompted to run a Gradle project sync so press *Sync Now* in the gold toolbar that should be
 visible.
 6. Open your projects `MainActivity` class and import the following package:
 ```java
 import com.podpoint.pptdeviceinfo.PPTDeviceInfoPackage;
 ```
 7. Find the line in your main activity class which has the following on it - `.addPackage(new MainReactPackage())`,
 add the following line below:
 ```java
 .addPackage(new PPTDeviceInfoPackage())
 ```
 8. Hit `Ctrl+R` and make sure the app runs!

## General Usage

Import the package into react native using the following:

```javascript
import DeviceInfo from '@pod-point/react-native-device-info';
```

Unfortunately the iOS and Android APIs differ slightly. This is because iOS and Android devices identify themselves
differently; however many of the parameters returned are similar.

### iOS Usage

The device info object will return the following properties:

```javascript
{
    appVersion: "1.0",
    buildNumber: "1",
    bundleId: "com.apple.UselessStocksApp",
    deviceId: "iPhone7,2",
    model: "iPhone 6",
    systemManufacturer: "Apple",
    systemName: "iPhone OS",
    systemVersion: "9.1"
}
```

If you've optionally enabled the device token functionality then you can access it using the following callback.
If the transform token parameter is set to true then all whitespace and `<>` charachters will be removed from the
token, if it is set to false then the token is returned in it's raw format.

```javascript
let transformToken = true;

DeviceInfo.deviceToken(transformToken, (token, error) => {
    console.log(token, error);
});
```

Should the device token be unavailable, the error object will provide you some useful information as to why. You
may need to request the user to enable push notifications - this isn't something which is in the scope of this
package so this functionality isn't available here.

### Android Usage

Android device info is returned as an object, there are no callbacks when this package runs on Android hardware:

```javascript
{
    appVersion: "1.0",
    buildNumber: 1,
    bundleId: "com.google.calculator",
    deviceToken: "APA91bFoi3lMMre9G3XzR1LrF4ZT82_15MsMdEICogXSLB8-MrdkRuRQFwNI5u8Dh0cI90ABD3BOKnxkEla8cGdisbDHl5cVIkZah5QUhSAxzx4Roa7b4xy9tvx9iNSYw-eXBYYd8k1XKf8Q_Qq1X9-x-U-Y79vdPq",
    model: "Google Nexus 5 - 5.0.0 - API 21 - 1080x1920",
    systemManufacturer: "Genymotion",
    systemName: "Android",
    systemVersion: "5.0",
    hardwareId: "11bf04d174814945"
}
```