it is normal. FCM token takes a while to be returned by firebase. listen on tokenRefresh handler
thanks @evollu could you please give me the example how can use tokenRefresh ?
I am using in this way:
FCM.on('refreshToken', (token) => {
console.log('Does it work'+token)
});
But it seems that not triggering
@azamkth Looking at the Usage example in the README it looks like you need to be using FCMEvent.RefreshToken.
FCM.on(FCMEvent.RefreshToken, token => {
console.log(token);
});
@alexdunne getting Cannot read property 'RefreshToken' of undefined
You need to import FCMEvent
import FCM, { FCMEvent } from "react-native-fcm";
i did but same error but bellow is working
FCM.getFCMToken().then(token => {
console.log('HelloNewToken: '+token);
});
Not sure then, just set it up myself at it works.
What if you console.log(FCMEvent);
You should see something like:
{
"DirectChannelConnectionChanged": "FCMDirectChannelConnectionChanged",
"Notification": "FCMNotificationReceived",
"RefreshToken": "FCMTokenRefreshed"
}
i did and getting undefined
I've created an expo example https://snack.expo.io/H1RnmEnkf
If you look at the preview you can see the output of FCMEvent.RefreshToken and JSON.stringify(FCMEvent).
right but when i did console.log(FCMEvent); I got "undefined". Could you please give me any suggestion why i am getting this ?
Can you show the code you're working with? If your code looks like the expo example then it should work.
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import FCM, { FCMEvent } from 'react-native-fcm';
componentDidMount: function() {
console.log(FCMEvent);
},
I'm not sure then. Maybe it's to do with the version you're using? I'm not familiar enough with the library to know for sure.
What do you get if you console.log(FCM)?
Also, not that it should matter, try moving the console.logs directly underneath your imports.
console.log(FCM) giving bellow ouput
{ getInitialNotification: [Function],
getFCMToken: [Function],
requestPermissions: [Function],
presentLocalNotification: [Function],
scheduleLocalNotification: [Function],
getScheduledLocalNotifications: [Function],
cancelLocalNotification: [Function],
cancelAllLocalNotifications: [Function],
removeDeliveredNotification: [Function],
removeAllDeliveredNotifications: [Function],
setBadgeNumber: [Function],
getBadgeNumber: [Function],
on: [Function],
subscribeToTopic: [Function],
unsubscribeFromTopic: [Function],
send: [Function] }
What version of the library are you using?
react-native-fcm": "^2.5.6" (in package.json)
Ah. That will be why then. The current version is 10.0.3.
Looking at the 2.5.6 version of index.js it looks like the event map isn't exported hence why you're getting undefined.
Sadly, I haven't used that version so I'm not sure what your issue could be. It may be worth upgrading to a more recent version if possible? However, @evollu may be able to help you with that version.
Sorry I couldn't be of any more help.
Could you tell me how i can update react-native-fcm ?
ok i will get back to you soon. thanks a lot for your help. one more question this update will not make any effect with current funcationality.
I expect as there have been several major versions since 2.5.6 some things will be different. However, I'm not certain what specifically will have changed.
@alexdunne I am using react-native 0.39.2 so for RN < 0.40.0, use [email protected] that' why I was using this version. any solution?
@azamkth you can use hardcode string 'FCMTokenRefreshed'
@evollu could you please give me example how i can use hardcode string 'FCMTokenRefreshed' ? and where i should use ?
FCM.on('FCMTokenRefreshed', token => {
console.log(token);
});
@evollu getting error: FCM event must be "refreshToken" or "notification.
And then i try bellow code:
FCM.on('refreshToken', (token) => {
console.log(token)
});
it seems not triggering at all
try delete the app and reinstall. You may or may not get refreshToken event depending on how quickly your device gets FCM token. If your device gets token before JS gets bootstrapped or your device already has a token, the event won't be called.
@azamkth Here is my code using react-native 0.39.2 & react-native-fcm 2.5.6.
FCM.getFCMToken().then(token => {
console.log("deviceToken ",token)
});
FCM.getInitialNotification().then(notification=>{
// Push Tap Navigation
});
this.notificationUnsubscribe = FCM.on('notification', (notification) => {
// there are two parts of notif. notif.notification contains the notification payload, notif.data contains data payload
if(notification.opened_from_tray){
// Push Tap Navigation
}
});
this.refreshUnsubscribe = FCM.on('refreshToken', (token) => {
console.log("refreshToken ",token)
// fcm token may not be available on first load, catch it here
});
@evollu @imbudhiraja I tried but the problem is still there (fcm token not available on the first load). I need to get device token on login view(and storing device token in the database with successful login). But unfortunately, it seems that not possible so far.
Check your internet connection. If you without it you cannot to take token.
@azamkth
I am the same problem, there are ways to solve it?
@evollu I am the same problem..
FCM.on('FCMTokenRefreshed', token => {
console.log(token);
});
it is not triggering!!!....
my version:
"react-native": "0.51.0",
"react-native-fcm": "^13.3.1",
Same issue, nothing triggering on APK build. Works fine on debug.
@evollu Is this fixed now in v14.2.0 as per #930 ?
@ASteinheiser Android should have been fixed a long time ago.
@evollu I am using v16.1.0 with RN v0.54.4 and
FCM.getFCMToken().then(token => {
console.log("token",token)
});
The token is always blank on debug and prod release.Please help. Thanks in advance.
closing this due to inactivity
@singhiskamal can you reproduce using the example project?