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.
npm install @pod-point/react-native-device-info --save
iOS Setup Guide
- Open up your React Native project in XCode, this is the
.xcodeprojfile in the
iosdirectory of your React Native project.
node_modules/@pod-point/react-native-device-info/iosin Finder and locate the
PPTDeviceInfo.xcodeprojpackage. Drag this file into the XCode project navigator. You can keep this in the
Librariesgroup along with all the other React Native packages.
- 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.aproduct was added. If not, expand the
PPTDeviceInfo.xcodeprojand drag this file in.
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:
- 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-infoto the header search path list and make sure that it is set to recursive.
- Ensure that your app delegate is correctly registering user notifications. You should have already completed this step if you're already using push notifications.
- In your
didRegisterForRemoteNotificationsWithDeviceTokendelegate, add the following line:
[PPTDeviceInfoProvider provideDeviceToken:[deviceToken description]];. This assumes that your delegate has called the device token
Android Setup Guide
- Open up your React Native project in Android Studio, this is the
androiddirectory in your React Native project.
- Expand Gradle Scripts from within the project tree and open
settings.gradle. Replace the line in the script which states
include ':app', ':pptdeviceinfo'(or append
':pptdeviceinfo'to the end of the include statement if you're already including other modules).
- Add the following line to the end of
project(':pptdeviceinfo').projectDir = new File(rootProject.projectDir, '../node_modules/@pod-point/react-native-device-info/android/library')
- Open up your
build.gradlefile and add the following line to the end of your dependancies section:
compile project(path: ':pptdeviceinfo')
- You should now be prompted to run a Gradle project sync so press Sync Now in the gold toolbar that should be visible.
- Open your projects
MainActivityclass and import the following package:
- Find the line in your main activity class which has the following on it -
.addPackage(new MainReactPackage()), add the following line below:
Ctrl+Rand make sure the app runs!
Import the package into react native using the following:
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.
The device info object will return the following properties:
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.
let transformToken = true;DeviceInfo;
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 device info is returned as an object, there are no callbacks when this package runs on Android hardware:
appVersion: "1.0"buildNumber: 1bundleId: "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"