react-native: PushNotificationIOS conflicting docs AND localNotification event is not firing after remote notif SDK integration

React Native version:

    System:
    OS: macOS 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
    Memory: 453.62 MB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 10.15.0 - /usr/local/bin/node
    Yarn: 1.12.3 - /usr/local/bin/yarn
    npm: 6.9.0 - /usr/local/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: 24, 26, 27, 28, 29
      Build Tools: 26.0.2, 27.0.3, 28.0.3, 29.0.0
      System Images: android-27 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom
      Android NDK: 14.1.3816874
  IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5522156
    Xcode: 10.3/10G8 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0
    react-native: 0.60.5 => 0.60.5
  npmGlobalPackages:
    create-react-native-app: 2.0.2
    react-native-cli: 2.0.1

Steps To Reproduce

  1. git clone git@github.com:geektimecoil/react-native-onesignal
  2. cd react-native-onesignal/examples/RNOneSignal/
  3. git checkout reproduce-local-notif-conflict (branch with local notif repro code)
  4. yarn
  5. Build and run the example app by:
    • Open the RNOneSignal project in XCode
    • Change the Signing Team and Bundle Identifier for both the RNOneSignal target as well as the OneSignalNotificationServiceExtension
      • The Service Extension bundle id should be <main-target-bunde-id>.OneSignalNotificationServiceExtension

Your AppDelegate.m should look like this after following the OneSignal (remote notifications) setup instructions and the PushNotificationIOS (local notifications) setup instructions.

One thing to note is that it seems like the PushNotificationIOS docs have conflicting instructions…which brings me to the first issue:

Part 1: The code in those docs says to add this to your AppDelegate.m:

 // Required for the localNotification event.
 - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
 {
  [RCTPushNotificationManager didReceiveLocalNotification:notification];
 }

However, it also says to add

// Define UNUserNotificationCenter
  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  center.delegate = self;

which in theory should break the former. It would be nice to clarify this discrepancy.

Part 2: After adding the OneSignal SDK (remote notifications), the event listener for localNotification no longer is triggered.

In the OneSignal example app you built in the reproduction steps, tap “Send Local Notifs”. You will see in the console that the console.log in the localNotification handler is never fired after tapping on the local notification.

This may be an issue on our side (OneSignal). However, it isn’t clear to us why this is happening and the documentation isn’t clear on how to properly handle both the old (deprecated) and new ways of handling local notifications.

A better local notification click handler would use userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler so we would love to see this used in a future RN version (Apple docs). This would be the only way to solve the compatibility issue between plugins for the click handler for iOS 10+ devices.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 7
  • Comments: 18 (4 by maintainers)

Commits related to this issue

Most upvoted comments

@safaiyeh React Native didReceiveLocalNotification method is still present in the code, can we remove it from the library first before removing it from the docs? 🙂

Also it looks like that RNTester is also using that handler (I’m not sure if there is a test related to that):


The @react-native-community/push-notification-ios team fixed the local notification issue for new iOS releases in this PR (hope this will shed some more light into the problem):

The docs for the AppDelegate.m part are confusing, as @rgomezp says didReceiveLocalNotification method should not be referenced anymore in the docs since its deprecated and should be be replaced by this, right ?

Screenshot 2020-09-17 at 13 09 41

Still not fixed. Any update from React Native???