Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Native: Get the same unique device ID after reinstalling the application

I’m writing an app in React-Native and need some help concerning identifying the device after reinstalling the application.

What I need:

  • Get a unique device ID for every device for both Android and iOS.
  • The same ID should be returned even if the user uninstalls the application and installs it again.

The closest to this I’ve come over is the getUniqueID() method in react-native-device-info. However, a different ID will be returned on iOS if the app is reinstalled since the returned value for this method is related to the vendor.

Have a great day!

like image 958
MisseMask Avatar asked Sep 20 '17 09:09

MisseMask


1 Answers

  1. Well, if you need it due security purposes (e.g. so nobody is abusing your API or premium content), you are looking for Device Check / App Attestation for iOS and Google Safety Net for Android. By using these libs, you will get a unique device token (on iOS) or attestation (on Android).

When using iOS, you can take this token, and set up two bits on a server hosted directly in Apple by using your own server as a middle-man (as you should not do it directly, from the mobile app).

According to Apple: Apple records the bits for you and reports the bits back to you, but you’re responsible for keeping track of what the bits mean. You’re also responsible for determining when to reset the bits for a given device; for example, when a user sells the device to someone else

Similarly, with Android - you just send attestation from device to server where it will be validated.

To use mentioned libs in React Native, you can either install corresponding libs:

  • https://github.com/dayitv89/react-native-ios11-devicecheck
  • https://github.com/rajivshah3/react-native-google-safetynet
  • plus you will need to implement verification part on your server

or if you are using Firebase libs (e.g. from rnfirebase.io), you can use AppCheck that uses SafetyNet and DeviceCheck / App Attestation underhood and comes also with easy server-side verification (also for non-Firebase resources).

  1. If you need a solution that is focused on pushing data from server to client, you are looking for a push notification token.

Libs:

  • https://rnfirebase.io/messaging/usage
  • https://github.com/zo0r/react-native-push-notification

As this token can change over time (by design), you should implement few services that support that / or potentially re-architect your app. Typically, tokens are stored under the user profile in your backend (or they are linked in some other way to the user that is using the device in the given time).

  1. If you are looking for something else, I think it's not possible.
like image 164
Stefan Majiros Avatar answered Sep 18 '22 08:09

Stefan Majiros