Skip to content

PushNotificationIOS.requestPermissions won't resolve if no event listeners are attached #13012

@frantic

Description

@frantic

Description

RCTPushNotificationManager uses startObserving to register for RCTRegisterUserNotificationSettings. According to the docs, the startObserving method won't be called until somebody subscribes to NotificationManagerIOS.

This means there is a scenario when the developer can call requestPermissions without subscribing to notifications first, but since RCTPushNotificationManager relies on NSNotificationCenter subscribtion, the result will never be returned.

This should be fairly straightforward to solve for somebody new to React Native. Feel free to send a PR!

Reproduction

Have this in your JS file

PushNotificationIOS.requestPermissions().then(console.log);

You'll see iOS permissions dialog, however pressing "Allow" won't resolve the promise and nothing will be printed to the console.

Solution

Change the code to this, then uninstall and run the app again (needed to reset iOS permissions cache):

PushNotificationIOS.addEventListener('localNotification', () => {});
PushNotificationIOS.requestPermissions().then(console.log);

Now "Allow" button will work as expected, the promise will be resolved and you'll see log entry.

Additional Information

  • React Native version: 0.42.0
  • Platform: iOS
  • Operating System: macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good first issueInterested in collaborating? Take a stab at fixing one of these issues.Help Wanted :octocat:Issues ideal for external contributors.Platform: iOSiOS applications.Resolution: LockedThis issue was locked by the bot.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions