Just upgraded to react native 0.61.5 and react native firebase (v5.5.7) getToken()
function doesn't seem to run or it just seems to hang on the await
.
I have this function:
async function updatePushNotificationsEnabled(isEnabled: boolean) {
return updateUser({ pushNotificationsEnabled: isEnabled, firebaseId: await getToken() })
}
which in turn is calling:
async function getToken() {
try {
return FCM().getToken();
} catch (error) {
return undefined;
}
}
If I follow https://rnfirebase.io/docs/v5.x.x/messaging/device-token I can't seem to get a token back from the server. If I try console.log(await getToken())
I don't get anything in console. If I console.log(FCM().getToken())
I get a promise in the console. What am I doing wrong? or am I needing to upgrade to the latest version of react native firebase?
I have also checked permissions and the permission on the device is on so returns true.
I do have a function to check for permissions but this is done earlier in the app and not at the point of what I am doing.
async function requestPermissionIfNeeded() {
try {
if (await FCM().hasPermission()) {
return true;
}
await FCM().requestPermission();
return await FCM().hasPermission();
} catch (error) {
return false;
}
}
What ended up working for us on iOS was updating the react native firebase library to v5.6.0
(as we aren't in a position to update to v6 yet).
This required us to update the underlying Podfile Firebase versions to ~6.13.0
as per the guide. Did a pod install
and it looks like the getToken
function is working again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With