invertase / react-native-notifee

Moved to https://github.com/invertase/notifee
https://invertase.io/blog/open-sourcing-notifee
Other
466 stars 31 forks source link

iOS listeners sometimes not being triggered #333

Closed divvyadmin closed 3 years ago

divvyadmin commented 3 years ago

We just added the notifee library to give us the ability to do "interactions". We are using this along side reat-native-firebase

For push notification interactions we are creating the payload partially on our servers, then creating locally with notifee.displayNotification()

I have both notifee.onForegroundEvent and notifee.onBackgroundEvent listeners set up correctly (I presume they are set up correctly because everything works perfectly on Android).

However on iOS, these listeners are not always triggered. When they are triggered, its the onForegroundEvent that is triggered , never the background (I believe this issue covers that)

It was really tricky because at first the listeners were working, then they weren't, at first I thought it was something I was doing wrong, but then I realized it was sporadic behavior with no code changes, like there is some race condition or something.

helenaford commented 3 years ago

hey, thanks for the report, do have some way of use reproducing the bug? I'll get the alpha release out this week so you can test the issue where the background listener is triggered during an onPress.

I'd recommend pulling down the repo and running the example app to see if the issue still occurs. Or/and, pasting any example code you have here to rule out any issue with the setup. Otherwise, I'm not sure how we'd debug this right now :( I've not seen any issues with the triggers not firing the event handlers on iOS personally. But, that doesn't say there's not an issue. If you can let us know in much detail as possible about it, that will be a great help.

mikehardy commented 3 years ago

for reference https://stackoverflow.com/help/minimal-reproducible-example

helenaford commented 3 years ago

Alpha release for #262 is published, hopefully, that resolves some of the issues you are having @divvyadmin.

divvyadmin commented 3 years ago

I installed the alpha release and on ios, built the app in xcode on a real device, close the app, and create a data only push notification.

Every time the app goes inactive or into the background I am calling notifee.setNotificationCategories() with the following payload:

[
  {
    "id": "SOME_CATEGORY",
    "actions": [
      {
        "id": "SOME_ID",
        "title":"Some title",
        "foreground":true
      }
    ]
  }
]

I get the following expected behavior

Then when I press the local push notification or the push notification "action" I expect the following behavior:

However, absolutely nothing is getting triggered, although the app is opening (since I set "foreground": true in the category)

I will attempt to get a minimal reproducible example when I get the time later this week.

divvyadmin commented 3 years ago

Ok, I feel like a crazy person now. After trying dozens of times with the same bad result, as soon as I posted the previous post above, I tried it again, and now it is working (the notifee.onBackgroundEvent() handler is triggering when local notification is clicked).

The only thing that has changed between the last post and this one is a few console.logs, opening/closing the app a few dozen times, sending a few dozen push notifications, and some time elapsing.

This is the sporadic behavior I was talking about.

mikehardy commented 3 years ago

If I recall correctly there is a slight pause between our native code hook and when we dispatch the event to the JS layer, in order to allow the JS layer to come up.

I wonder if you loaded your machine heavily (or, I suppose this is an iOS device? if you cause it to work really hard somehow) during test, this would be reproducible

divvyadmin commented 3 years ago

I'm closing this issue.

It turns out my problem was in the upgrade from react-native-firebase v5 to the latest, I failed to remove the following code from the AppDelegate.swift:

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        Intercom.setDeviceToken(deviceToken)
    }

Thanks for being responsive and for making such great products!