3

I want to use deviceId, deviceToken, deviceType for the login purpose so how do I get it. Can someone please help me out.

Rajat Verma
  • 420
  • 1
  • 7
  • 19

3 Answers3

2

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

Kabir
  • 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
  • Yes,its a different in multiple device with same authentication – Kabir Aug 17 '19 at 16:52
  • 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
1

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

Alongkorn
  • 3,968
  • 1
  • 24
  • 41
-1

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/

rewdt
  • 7
  • 1