Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fcm token not available on first load react native (android) #1021

Closed
roeib opened this issue Aug 14, 2018 · 14 comments · May be fixed by #1078
Closed

fcm token not available on first load react native (android) #1021

roeib opened this issue Aug 14, 2018 · 14 comments · May be fixed by #1078

Comments

@roeib
Copy link

roeib commented Aug 14, 2018

"react-native": "0.55.4",
"react-native-fcm": "^14.1.3",
All Android  devices

after install the apk the app dont get fcm token
only after close the app and open again everything is fine.

FCM.getFCMToken().then(token => {
console.log("TOKEN (getFCMToken)", token);
//send to the server
});

FCM.on('FCMTokenRefreshed', token => {
  console.log("tokewn", token);
      //send to the server
});

please help :)

@roeib
Copy link
Author

roeib commented Aug 14, 2018

@evollu

@evollu
Copy link
Owner

evollu commented Aug 17, 2018

do you have same issue in debug mode?

@roeib
Copy link
Author

roeib commented Aug 18, 2018

@evollu on the emulator i dont have this problem

@Seemapadiya
Copy link

@evollu in release build getting same issues
after install the apk the app dont get token it giving null and then after relaunch the app getting token
is there any other thing to do or am i doing wrong any thing, because in debug build its working perfectly fine.
Please help

@evollu
Copy link
Owner

evollu commented Aug 28, 2018

it takes a while to get firebase token. i wonder if it could be a firebase bug

@Seemapadiya
Copy link

Seemapadiya commented Aug 28, 2018

Okk but now what should I do to handle this condition , can you please help me out

@evollu
Copy link
Owner

evollu commented Aug 28, 2018

listen on FCM.on('FCMTokenRefreshed', token => { and call FCM.getFcmToken on app start. The token should be there eventually.
You can save the token in storage for future compare to see if it actually changed

@Seemapadiya
Copy link

Ok i will try it and let you know if its works or not,
Thank you for help

@Seemapadiya
Copy link

@evollu Thank you very much, its working fine in release build.

@Udbhav12
Copy link

@Seemapadiya I am facing the same issue. Could you please share code snippet?

@Seemapadiya
Copy link

Seemapadiya commented Aug 29, 2018

@Udbhav12 previously i was used this method on my app start and its working fine in debug
FCM.getFCMToken().then(token => {
console.log("FCM >>>token>>" + token)
});
For the release build issues i have to implement this method on app start and saved token in storage
FCM.on('FCMTokenRefreshed', token => {
console.log('FCMTokenRefreshed',token);
});
if we didn't find token in FCM.on method but i have always get token in this method FCM.on('FCMTokenRefreshed', token => {})

@evollu evollu closed this as completed Aug 30, 2018
@havinhthai
Copy link

@Seemapadiya Did you save parameter token in FCM.on('FCMTokenRefreshed', token => {}) and FCM.getFCMToken() to store?

Example:

FCM.on('FCMTokenRefreshed', token => {
    AsyncStorage.setItem('NOTIFICATION_TOKEN', token);
});

FCM.getFCMToken().then(token => {
   AsyncStorage.setItem('NOTIFICATION_TOKEN', token);
});

@Seemapadiya
Copy link

Yes direct store in to my model class

@sarathbabutemburu
Copy link

sarathbabutemburu commented May 8, 2019

@evollu please help me i am not getting FCM token in release apk below is my code

FCM.on('FCMTokenRefreshed', token => {});

componentDidMount() {
FCM.getFCMToken().then(token => {
console.log("TOKEN (getFCMToken)", token);
this.props.savePushNotificationToken(token)
});
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants