react-native-onesignal icon indicating copy to clipboard operation
react-native-onesignal copied to clipboard

[Bug]: stale/wrong data in getPermissionAsync and requestPermission methods

Open mbardauskas opened this issue 1 year ago • 6 comments

What happened?

SDK returns wrong results for getPermissionAsync and requestPermission after user enables permissions via settings.

  const subscribe = async (): Promise<boolean> => {
    if (await OneSignal.Notifications.getPermissionAsync()) {
      if (!(await OneSignal.User.pushSubscription.getOptedInAsync())) {
        OneSignal.User.pushSubscription.optIn();
      }
      // ... other subscription requirements
      return true;
    } else {
      const fallbackToSettings = true;
      if (await OneSignal.Notifications.canRequestPermission()) {
        const enabled = await OneSignal.Notifications.requestPermission(fallbackToSettings);
        // ... other subscription requirements
        return enabled;
      } else {
        // ... lead to fallback view
      }
    }
  }

Am I using the SDK wrong?

Steps to reproduce?

1. install react-native-onesignal v5.1.0
2. launch app on Android
3. disable notifications via phone settings for the app
4. launch app again
5. call requestPermission with fallback to settings
6. press Settings in the permission prompt
7. enable notifications in the phone settings
8. go back to the app
9. requestPermission returns false, further calls to getPermissionAsync also returns false

What did you expect to happen?

when user enabled notifications in settings requestPermission should have returned true as per contract. Furthermore, getPermissionAsync should return true too

React Native OneSignal SDK version

5.1.0

Which platform(s) are affected?

  • [ ] iOS (not tested)
  • [X] Android

Relevant log output

No errors in logs

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

mbardauskas avatar Mar 18 '24 12:03 mbardauskas

@mbardauskas thank you for reaching out! We are looking into this.

jennantilla avatar Mar 19 '24 19:03 jennantilla

any update? I have a similar problem. after granting the notification permission, the correct data does not come unless I exit the app and log in. @jennantilla

MuazzezA avatar May 30 '24 08:05 MuazzezA

@MuazzezA @jennantilla Not sure, but this might be related to #1726

hrastnik avatar Aug 08 '24 02:08 hrastnik

Hello everyone! Thanks for your patience on this. Can you please try updating to Release 5.2.3 and let us know if the issue still occurs? Thanks!

jennantilla avatar Aug 20 '24 19:08 jennantilla