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

[Bug]: Notification.canRequestPermission always returns true #1560

Closed
2 of 3 tasks
ChromeQ opened this issue Sep 18, 2023 · 4 comments
Closed
2 of 3 tasks

[Bug]: Notification.canRequestPermission always returns true #1560

ChromeQ opened this issue Sep 18, 2023 · 4 comments

Comments

@ChromeQ
Copy link

ChromeQ commented Sep 18, 2023

What happened?

According to the docs the Notification.canRequestPermission() should "Return true if the device has never been prompted for push notification permission."
https://documentation.onesignal.com/docs/mobile-sdk#checking-if-a-permissions-prompt-can-be-displayed

However I am finding that the method always returns true, despite being shown the permission request (using Notifications.requestPermission()) and denying it multiple times.

I have only tested Android but may also affect iOS but not tested.

Steps to reproduce?

const canAsk = await OneSignal.Notifications.canRequestPermission();
console.log('CAN ASK', canAsk); // <-- Always `true`

if (canAsk) {
  const granted = await OneSignal.Notifications.requestPermission();
  console.log('REQUESTING', granted);
} else {
  console.log('REQUESTING FAILED');
}

What did you expect to happen?

Expected the canAsk method to return false when the permission has been denied

React Native OneSignal SDK version

5.0.0

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ShivamKJJW
Copy link

ShivamKJJW commented Sep 20, 2023

In android it has been set to behave that way.
image

RNOneSignal.java>Line 439

@ChromeQ
Copy link
Author

ChromeQ commented Sep 20, 2023

What! That's crazy! Why would it do that? Is there no way to determine if I can/should show a custom message about turning on notifications in the settings?

Do you work at OneSignal? Can somebody at OneSignal explain this? The description (and the fact it is a Boolean) suggests it could be true or false.

@ovidb
Copy link

ovidb commented Sep 26, 2023

This is indeed "a bit" unexpected. Maybe that should be the case for android 12 and older but for everything this seems very wrong.

@nan-li
Copy link
Contributor

nan-li commented Sep 28, 2023

Hi everyone, thanks for reporting this and we have fixed the Android implementation in the latest release 5.0.1.

@nan-li nan-li closed this as completed Sep 28, 2023
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

4 participants