This repository was archived by the owner on Apr 8, 2025. It is now read-only.
This repository was archived by the owner on Apr 8, 2025. It is now read-only.
firebase.messaging().requestPermission() does nothing on android #241
Closed
Metadata
Metadata
Assignees
Labels
No labels
Activity
mikehardy commentedon Dec 15, 2019
You are neither proposing a direct problem with the documentation nor proposing a change, so I don't see an issue
requestPermission() is required in order to ask the operating system (on iOS) to listen for messages as well on v5
VilleMiekkoja commentedon Dec 15, 2019
The docs are wrong in here: https://github.com/invertase/react-native-firebase-docs/blob/master/docs/messaging/receiving-messages.md:
"If the user has not already granted permissions, then you can prompt them to do so, as follows:
try {
await firebase.messaging().requestPermission();
// User has authorised
} catch (error) {
// User has rejected permissions
}
"
That is not true on Android. If user has not granted the permission, this does not prompt them to do so.
mikehardy commentedon Dec 15, 2019
On android it always resolves to true, because android doesn't require permission.
It is however still a requirement in order to listen for messages in the background as that's the signal in v5 to attach a listener.
On iOS if the user has already granted permission or the user has blocked permission they won't get a prompt either.
My suggestion at this point?
react-native-permissions
to do the actual permission management (it's a much better module for it, including for blocked permission handling etc), and only after you have permissions where you want them call requestPermission (which at that point can just be thought of as "register on native side to listen for messages"If you hit the edit button on the top right and cooked something up, we could get it merged
VilleMiekkoja commentedon Dec 15, 2019
But android does have the notification permission options for that in settings. I used library https://github.com/riwu/react-native-open-notification to open the permission settings. Are you saying that it doesn't matter whether the user has allowed notifications on android, that he will receive those anyway? I thought the user agrees on the permissions during installation. But then he can deny that permission later on. And if he has denied those permissions, then one could think from these docs that calling requestPermissions() would prompt them to do so. So the quick hotfix for the docs is to modify that sentence.
I tested and you are not required to requestPermission() (on Android) in order to get notifications. Even when the app is closed, you will get notifications without calling requestPermission.
VilleMiekkoja commentedon Dec 15, 2019
#242
mikehardy commentedon Dec 15, 2019
on Android? What versions tested? on iOS? what versions.
All of this stuff changes every API it seems. You must be specific.
VilleMiekkoja commentedon Dec 15, 2019
Android 8.1.0, Nexus 6P. Kernel version: 3.10.73-g7bf0310 (gcc version 4.9.x-google 20140827 (prerelease) /GCC)). android-build@abfarm245 #1. Made on Thur Mar 15 22:25:39 UTC 2018. Also tested on android emulator too, Nexus 5. Version of react-native-firebase was version 5.2.5
mikehardy commentedon Dec 15, 2019
Try an Android 10 emulator with react-native-permissions requestNotification vs react-native-firebase requestPermission - I think it'll pop a permission dialog in react-native-permissions because it's permission implementation is more up to date than react-native-firebase v5
That said, react-native-firebase 5.2.5 is not deployable I don't think. firebase apps will crash with pods lower than 6.5 on ios13+, which implies react-native-firebase 5.5+ series, and react-native-firebase 5.5+
VilleMiekkoja commentedon Dec 15, 2019
Ok, so you mean I should update to atleast 5.5? If I remember right that requires newer version of react-native also -> need to update that too. Don't wanna do that unless no other option, since every update process of react-native has been very painful.
mikehardy commentedon Dec 16, 2019
Understood - react-native 0.58 to 0.59 was not so bad at least, although 0.59 to 0.60 is a HUGE leap, with 0.61 then being tiny again. Not sure if these are your exact versions but the upgrade helper dialed in from where you are to where you want to go is very very useful: https://react-native-community.github.io/upgrade-helper/?from=0.58.6&to=0.59.10
wincod75 commentedon Feb 6, 2020
Any update on this one? I'm on RN 59, noticed the same issue, iOS prompts for notifications, Android does not, but auto defaults to true. Using RNFB V5.
mikehardy commentedon Feb 6, 2020
Use react-native-permissions if at all possible. It is by far the best way to manage permissions as it is focused on that, whereas here it is naturally just an afterthought