Skip to content
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
@VilleMiekkoja

Description

@VilleMiekkoja

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.

Activity

mikehardy

mikehardy commented on Dec 15, 2019

@mikehardy
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

VilleMiekkoja commented on Dec 15, 2019

@VilleMiekkoja
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

mikehardy commented on Dec 15, 2019

@mikehardy
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

VilleMiekkoja commented on Dec 15, 2019

@VilleMiekkoja
Author

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

VilleMiekkoja commented on Dec 15, 2019

@VilleMiekkoja
Author
mikehardy

mikehardy commented on Dec 15, 2019

@mikehardy
Collaborator

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

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

VilleMiekkoja

VilleMiekkoja commented on Dec 15, 2019

@VilleMiekkoja
Author

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

mikehardy commented on Dec 15, 2019

@mikehardy
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

VilleMiekkoja commented on Dec 15, 2019

@VilleMiekkoja
Author

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

mikehardy commented on Dec 16, 2019

@mikehardy
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

wincod75 commented on Feb 6, 2020

@wincod75

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

mikehardy commented on Feb 6, 2020

@mikehardy
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      firebase.messaging().requestPermission() does nothing on android · Issue #241 · invertase/react-native-firebase-docs