I'd like to use Firebase for push notifications and this is my setup:
Firebase.messaging().onTokenRefresh(token => {
storeNotificationToken(token);
});
Firebase.messaging().requestPermissions();
Firebase.messaging().onTokenRefresh never fires and according to Xcode logs it seems like it tries to fire the event before my listener is registered, even though I'm doing it as early as I possible (even tried index.ios.js).
Just to clearify, this is when the app is installed on the phone and before I accepted the permissions dialog.
Using getToken() manually and sending push notifications works just fine, but I shouldn't need to call getToken, right?
Xcode logs:
2017-12-12 09:30:52.976644+0100 FCM registration token: <token>
2017-12-12 09:30:52.977 [warn][tid:main][RCTEventEmitter.m:54] Sending `messaging_token_refreshed` with no listeners registered.
2017-12-12 09:30:53.636 [info][tid:com.facebook.react.JavaScript] 'onTokenRefresh: listener:', [Function]
Same here.
Thanks for flagging this - we will address this as part of the FCM overhaul that we plan on doing for the next major release: https://github.com/invertase/react-native-firebase/issues/595
I still have this error.
"react": "^16.2.0",
"react-native": "^0.52.1",
"react-native-firebase": "^3.2.2",
same error here
This should be in the documentation until its fixed.
Workaround that works pretty well, request current token manually at regular intervals such as app open.
@hegelstad do u have an example of this?
As stated above, this will be resolved as part of #595 which is currently well underway
@sibelius, considering firebase.messaging().getToken() is a quite cheap call, just call it regularly, it will always contain the latest token. The downside is the increased data usage, so dont update it too often.
Good news, the long awaited alpha of our messaging and notifications overhaul is now available!!
Check out the release notes here: https://github.com/invertase/react-native-firebase/releases/tag/v4.0.0-alpha.1
If you have any comments and suggestions or want to report an issue, come find us on Discord
Seems like it not works. At the first time, a token is null
"version": "4.0.4"
componentDidMount() {
firebase.messaging().getToken().then((token) => {
if (token) {
this.setState({token: 'T2' + token})
}
});
firebase.messaging().onTokenRefresh((token) => {
if (token) {
this.setState({token: 'T1' + token})
}
});
}
On a next start, it works.. T2xsdgrw34324...
@chrisbianca which is the right way and place to call onTokenRefresh
?,
In Android Studio's LogCat I see this message
D/RNFInstanceIdService: onTokenRefresh event received
but it doesn't trigger the call to onTokenRefresh
I put at componentDidMount()
.
As others have pointed out, it is not called. I am using version 4.0.6
with react native 0.55.3
.
For now, as @hegelstad mentions, calling firebase.messaging().getToken()
regularly is the way to go.
Most helpful comment
Good news, the long awaited alpha of our messaging and notifications overhaul is now available!!
Check out the release notes here: https://github.com/invertase/react-native-firebase/releases/tag/v4.0.0-alpha.1
If you have any comments and suggestions or want to report an issue, come find us on Discord