OneSignal / react-native-onesignal

React Native Library for OneSignal Push Notifications Service
Other
1.57k stars 374 forks source link

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

Open mbardauskas opened 6 months ago

mbardauskas commented 6 months ago

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?

Relevant log output

No errors in logs

Code of Conduct

jennantilla commented 6 months ago

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

MuazzezA commented 4 months ago

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

hrastnik commented 1 month ago

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

jennantilla commented 1 month ago

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!