Skip to content

getInitialNotification is always returning null #24

Open
@filipecrosk

Description

@filipecrosk

Bug

I can't get getInitialNotification() to work, its always returning null. Regular notification when the app is already open is working fine, but if the app is closed and I receive a new notification it will ways return null for me.

Environment info

React native info output:

System:
    OS: macOS 10.14.6
    CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
    Memory: 1.39 GB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 8.10.0 - ~/.nvm/versions/node/v8.10.0/bin/node
    Yarn: 1.17.0 - /usr/local/bin/yarn
    npm: 5.6.0 - ~/.nvm/versions/node/v8.10.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
    Android SDK:
      API Levels: 28
      Build Tools: 28.0.3, 29.0.1
      System Images: android-Q | Google Play Intel x86 Atom
  IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5692245
    Xcode: 10.3/10G8 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6
    react-native: 0.60.4 => 0.60.4
  npmGlobalPackages:
    react-native-cli: 2.0.1

Library version: 1.0.2

Steps To Reproduce

  1. Install the library
  2. Add all settings to AppDelegate.m
  3. Add code to your app
  4. Send a notification
componentDidMount() {
    PushNotificationIOS.addEventListener('notification', function(notification) {
      console.log('Log - notification is open', notification);
      if (!notification) {
        return;
      }
      const data = notification.getData();
      Alert.alert(JSON.stringify({ data, source: 'CollapsedApp' }));
    });

    PushNotificationIOS.getInitialNotification().then(notification => {
      console.log('Log - notification from closed', notification);
      if (!notification) {
        return;
      }
      const data = notification.getData();
      Alert.alert(JSON.stringify({ data, source: 'ClosedApp' }));
    });
    PushNotificationIOS.requestPermissions();
  }

...

A code sample can be found here https://github.com/filipecrosk/react-native-push-notification-ios-test

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions