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]: The requestPermission method for notifications returns a Promise<array> on iOS. #1655

Open
2 of 3 tasks
WooMinGy opened this issue Feb 23, 2024 · 3 comments
Open
2 of 3 tasks

Comments

@WooMinGy
Copy link

WooMinGy commented Feb 23, 2024

What happened?

react-native: 0.73.2
device: iphone 12 mini
iOS version: 17.3.1
onesignal version: 5.0.5

I implemented actions to change based on whether the return value of requestPermission is true or false. However, the actions did not occur as specified on iOS. Upon checking, I found that the returned value was coming in as an array.

Below is a photo of my code and the result values confirmed via console.log.

  const requestPermission = useCallback(async () => {
    const isSucceed = await OneSignal.Notifications.requestPermission(true);

    if (Platform.OS === 'ios') {
      console.log('isSucceed: ', isSucceed);
      console.log(`
        type: ${typeof isSucceed}
        isArray: ${isArray(isSucceed)}
      `);

      return isArray(isSucceed) ? isSucceed[0] : isSucceed;
    }

    return isSucceed;
  }, []);

image

Steps to reproduce?

1. Install v5.0.5 
2. Launch the app on iOS device
3. Use the requestPermission method for notifications with console.log like my code

What did you expect to happen?

image

It should have returned a Promise as the specified type. On Android, it correctly returns a boolean, but on iOS, it is returning a Promise<boolean[]> instead.

React Native OneSignal SDK version

Release 5.0.5

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
@nan-li
Copy link
Contributor

nan-li commented Feb 23, 2024

Hi @WooMinGy, thank you for reporting this bug. We will make the fix to return boolean as expected on iOS.

@WooMinGy
Copy link
Author

@nan-li , thank you for checking the reporting quickly.
Please let me know after it has been fixed.

@ChromeQ
Copy link

ChromeQ commented Apr 28, 2024

I am also falling into this issue, any updates since Feb @nan-li?

The workaround in the meantime is to override the types and unwrap the array:

// FIXME: iOS returns a boolean tuple so unwrap it to provide a boolean as expected
// @see https://github.com/OneSignal/react-native-onesignal/issues/1655
const value = (await OneSignal.Notifications.requestPermission(true)) as boolean | [boolean];
const granted = Array.isArray(value) ? value[0] : value;

// `granted` is now always a boolean as per the types

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

3 participants