React Native Get Android iOS Device Unique ID Dynamically Example

Every mobile phone device in the world has its unique ID(Identify Signature) which makes with the combination of Alphabetic and Numeric characters. Unique device ID is used in Push Notification, identify a device uniquely at login app and most of money making app’s usages this to prevent multiple app installation in same device. Both android and iOS devices supports Unique ID and using the react-native-device-info NPM library we can easily retrieve Get Android iOS Device Unique ID Dynamically on button click in Android iOS react native application.

Contents in this project Get Android iOS Device Unique ID Dynamically on Button Click in iOS Android React Native App:

1. Open your react native project folder in Command Prompt / Terminal.

2. Execute the
npm install save reactnativedeviceinfo@0.11.0 command in your react native’s project like i did in below screenshot.


3. Now we need to execute
reactnative link reactnativedeviceinfo command in order to link this installed library to our current react native project.

4. Import Platform, StyleSheet, View, Text and TouchableOpacity component in your project.

5. Import react-native-device-info module in your app using a variable named as DeviceInfo. We would use this object to retrieve device unique id.

6. Create constructor() in your project and make a State named as DeviceID , this state is used to hold the Unique device id.

7. Create a function named as getDeviceID(), Inside this function we would simply get the unique device id using DeviceInfo.getUniqueID() method and store this into State. We would call this function on Button onPress event.

8. Create a Root View in render’s return block and Inside this View would make a Text component and 1 TouchableOpacity button.

9. Creating Style.

10. Complete source code for App.js File :

Screenshot in Android device:

Get Android iOS Device Unique IDScreenshot in iOS device: