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]: permissionChange listener is not giving the correct hasPermission value until background/foreground #1707

Open
2 of 3 tasks
Chasty opened this issue May 14, 2024 · 2 comments

Comments

@Chasty
Copy link

Chasty commented May 14, 2024

What happened?

At the latest sdk, the listener permissionChange is not giving the correct value in a specific scenario when you enable the permission check from phone settings only when tapping on SETTINGS when notifications not available.

it first gives the value of true, that means the permission check is enabled, but after some milliseconds it returns a false value.

related code.

useEffect(() => {
    const permissionChangedHandler = async (hasPermission: boolean) => {
      console.debug(
        'PermissionsStore.permissionChangedHandler hasPermission?',
        hasPermission,
      );

      if (hasPermission) {
        OneSignal.User.pushSubscription.optIn();
      }
      setIsEnabled(hasPermission);
    };
    OneSignal.Notifications.addEventListener(
      'permissionChange',
      permissionChangedHandler,
    );
  }, []);

const hasPermission = await OneSignal.Notifications.getPermissionAsync();

And then, using the method above to get the permission value is giving all the time a false value until you background/foreground.

Screen.Recording.2024-05-14.at.15.32.44.mov

Steps to reproduce?

1. Install react-native-onesignal: 5.1.3
2. Open the app.
3. Register the listener permissionChange.
4. Go to phone settings page to disable the notifications permission check.
5. Go back to the app, the listener gives you a correct value of false for the permission check.
6. Since permision check is disabled, a prompt to go to phone notifications settings appears.
7. Tap on `Settings`
8. Enable the push notifications permission check.
9. Go back to the app, the listener gives you the value of true and after some milliseconds it gives you another value of false which is incorrect.
10. Also when you try to get the `getPermissionAsync` gives you a false value which is wrong.

What did you expect to happen?

1. Install react-native-onesignal: 5.1.3
2. Open the app.
3. Register the listener permissionChange.
4. Go to phone settings page to disable the notifications permission check.
5. Go back to the app, the listener gives you a correct value of false for the permission check.
6. Since permision check is disabled, a prompt to go to phone notifications settings appears.
7. Tap on `Settings`
8. Enable the push notifications permission check.
9. Go back to the app, the listener should give you the value of true.
10. Also when you try to get the `getPermissionAsync` should give you the value of true.

React Native OneSignal SDK version

5.1.3

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

No output.

Code of Conduct

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

Chasty commented May 14, 2024

If you want to reproduce it, try to run on a physical android phone, and also I've created the repository, so u can take a look there.

https://github.com/Chasty/onesignal-issue

@Chasty
Copy link
Author

Chasty commented Jun 6, 2024

@nan-li Hello, could u able to reproduce this?

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

1 participant