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

firebase.messaging().requestPermission() does nothing on android #241

Closed
VilleMiekkoja opened this issue Dec 15, 2019 · 12 comments
Closed

Comments

@VilleMiekkoja
Copy link

VilleMiekkoja commented Dec 15, 2019

Push notification permissions are automatically requested during installation for android.

The method requestPermission() does not open the permission prompt, atleast not on android. It seems to always resolve the promise, regardless of the case.

@mikehardy
Copy link
Collaborator

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
Copy link
Author

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
Copy link
Collaborator

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?

  • propose a PR that indicates requestPermission is required in order to listen for messages
  • include in that PR a recommendation to use 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
Copy link
Author

VilleMiekkoja commented 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
Copy link
Author

#242

@mikehardy
Copy link
Collaborator

on Android? What versions tested? on iOS? what versions.

All of this stuff changes every API it seems. You must be specific.

@VilleMiekkoja
Copy link
Author

VilleMiekkoja commented 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
Copy link
Collaborator

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
Copy link
Author

VilleMiekkoja commented 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
Copy link
Collaborator

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
Copy link

wincod75 commented 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
Copy link
Collaborator

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

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

No branches or pull requests

3 participants