Skip to content

PushNotificationIOS.requestPermissions never resolves in RN 0.56.0 #7

Open
@cpojer

Description

@cpojer
Contributor

This issue was originally created by @jongirard as facebook/react-native#20821.


(Related issue marked as fixed but problem still exists: facebook/react-native#9105)

Environment

    System:
      OS: macOS High Sierra 10.13.5
      CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
      Memory: 29.44 MB / 16.00 GB
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 10.5.0 - /usr/local/bin/node
      Yarn: 1.7.0 - /usr/local/bin/yarn
      npm: 6.1.0 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
    IDEs:
      Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.4.1 => 16.4.1 
      react-native: 0.56.0 => 0.56.0 
    npmGlobalPackages:
      react-native-cli: 2.0.1

Description

As per the React Native documentation, PushNotificationIOS.requestPermissions method should return a promise to wait for user input, but nothing is ever returned. I've also tried adding an event listener in componentWillMount like PushNotificationIOS.addEventListener('register', (token) => {}); which also does not resolve the requestPermissions promise.

Reproducible Demo

PushNotificationIOS.requestPermissions().then((permissions) => console.log(permissions));

Activity

rafaellincoln

rafaellincoln commented on Feb 21, 2019

@rafaellincoln
Collaborator

@jongirard Can you test again please?

chr4ss1

chr4ss1 commented on Apr 19, 2019

@chr4ss1

If you'd like the requestPermissions to return something for sure, you need to ensure that

A) you take care of the case where 'register' event never happens

B) have fail-safe timeout which triggers after 7 seconds of no promise return.

return new Promise((resolve, reject) => {
                    PushNotificationIOS.addEventListener('registrationError', (message, key) => {
                        LogService.error(message);
                        resolve(null);
                    });
                    PushNotificationIOS.addEventListener('register', (token) => {
                        resolve(token);
                    });

                    PushNotificationIOS.requestPermissions().then((w) => {
                        if (w && w.badge === 0 && w.alert === 0 && w.sound === 0) {
                            resolve(null);
                        }
                    }, 
                    (x) => {
                        resolve(null);
                    });

                     setTimeout(() => resolve(null), 7000);
                });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @cpojer@jsamr@chr4ss1@rafaellincoln

        Issue actions

          PushNotificationIOS.requestPermissions never resolves in RN 0.56.0 · Issue #7 · react-native-push-notification/ios