androidreact-nativedevicetoken

How to get the device token at the time of registration in react native


How do i get the device token when a user is registered in an app.The purpose is that i want to send push notification using fcm. Can anybody please help ?


Solution

  • When I did kinda the same thing I went with this lib: https://github.com/evollu/react-native-fcm

    Which I think works great btw.

    When the user clicks on the register button or whatever, I do:

    FCM.getFCMToken().then(token => {
        //Send register request
    });
    

    The token can change as well, so whenever the app is started I compare the existing key from AsyncStorage and if it has changed I'll use the same procedure to update the key backend.

    Hope this helps, good luck.