I want to use deviceId, deviceToken, deviceType for the login purpose so how do I get it. Can someone please help me out.
-
What have you tried so far ? – Dhruv Aug 16 '19 at 14:45
-
nothing as I can't get any perfect solution to get that. – Rajat Verma Aug 16 '19 at 14:55
-
`deviceId` is deprecated and will be removed in Expo SDK 44, see my answer here https://stackoverflow.com/a/68553627/7944610 – Morris S Jul 28 '21 at 02:26
3 Answers
1.GET DEVICE ID:
To get the device information in React Native will use the react-native-device-info library. getDeviceId() is method for getting id.
For example code:doc
2.GET DEVICE TYPE:
Using the Platform module:
React Native provides a module that detects the platform in which the app is running. You can use the detection logic to implement platform-specific code. Use this option when only small parts of a component are platform-specific.
import {Platform, StyleSheet} from 'react-native';
const styles = StyleSheet.create({
height: Platform.OS === 'ios' ? 200 : 100,
});
3.DEVICE REGISTRATION TOKEN:
Device token is a unique key.Different service gateways has different method to implement and get token.Below is example for firebase device token.On initial startup of your app, the Firebase Cloud Messaging SDK generates a registration token for the client app instance.
For Retrieve the current registration token in firebase:
const fcmToken = await firebase.messaging().getToken();
if (fcmToken) {
// user has a device token
} else {
// user doesn't have a device token yet
}
For more info:doc

- 852
- 7
- 11
-
for device token why firebase service...what if i am using own server. – Rajat Verma Aug 16 '19 at 15:12
-
you can use react-native-device-token library,and if you have your own service ->then you should implement method for getting token from service documentation. – Kabir Aug 16 '19 at 15:18
-
does device token is specific to phone or user. As I am new to it so I don't no how it works.I am using device token because in login api which i am using there is a required field of these things so I don't know why these are requiring. – Rajat Verma Aug 16 '19 at 15:28
-
Device token is app-specific,but not device specific. Device token will be different and unique for multiple apps in same device. – Kabir Aug 16 '19 at 15:31
-
and what if same user is logged in multiple device with same user name – Rajat Verma Aug 16 '19 at 16:02
-
-
If you have some more query,let me know.or if you found helpful answer , please accept the answer and close question. – Kabir Aug 26 '19 at 15:00
-
Just a reminder that the `react-native-device-info` library is not supported by managed expo apps. The equivalent library Expo Device (https://docs.expo.dev/versions/latest/sdk/device/) does not return the device id. – Saulo M May 12 '23 at 19:43
To get deviceId on expo without ejecting, you can get it by
const deviceId = Expo.Constants.deviceId;
related link: https://forums.expo.io/t/help-getting-the-deviceid/12670

- 3,968
- 1
- 24
- 41
-
Try not to use this constant as it will change if you reinstall the app – Jim Yu Dec 17 '20 at 20:29
-
2
-
Since native code and expo do not mix you might want to try out a package like expo-device. It is quite straight-forward to use. check out the documentation here https://docs.expo.io/versions/latest/sdk/device/

- 7
- 1