notifee icon indicating copy to clipboard operation
notifee copied to clipboard

iOS push notification show up sometimes after opening the app

Open fgagneten opened this issue 1 year ago • 10 comments

Issue Summary: We are encountering an issue where iOS users occasionally experience a delay in receiving push notifications until they open the app. The problem seems to be inconsistent, as notifications are generally delivered promptly, but some users report receiving them only after launching the application.

Environment:

@notifee/react-native version: 7.8.0 @react-native-firebase/messaging version: 18.6.1 react-native version: 0.72.6 Additional Context:

We have implemented the setBackgroundMessageHandler in our app, which is utilized to log whether a user receives a notification or not. This helps us determine whether to resend notifications or not to make sure they always receive the notifications.

In the specific case reported, the setBackgroundMessageHandler was triggered, as evidenced by the database record indicating that the user received the notification pretty much the same hour/minutes/seconds the notification was delivered)

Despite the successful execution of setBackgroundMessageHandler, the user claims that the notification was displayed on their device only after opening the app. It's worth noting that the same user received notifications without any issues the previous weeks.

Steps to Reproduce: Unfortunately, we haven't been able to consistently reproduce the issue ourselves, making it challenging to identify the root cause.

Expected Behavior: Push notifications should be consistently displayed to users in a timely manner, regardless of whether the app is open or closed.

Actual Behavior: Notifications are occasionally delayed until the user opens the app, even though the setBackgroundMessageHandler has been executed and logged appropriately.

Additional Information: Are there any known compatibility issues between the mentioned library versions? Any insights on potential changes or updates that could address this intermittent delay?

Device reported the error: ios 16.1.2, iphone 13

This is how I'm displaying the notification (I don't think this is really required due to this is inside the onMessageRecieved that is called on foreground):

await notifee.displayNotification({
  id: notificationId,
  title: remoteMessage.notification?.title,
  body: remoteMessage.notification?.body,
  data: remoteMessage.data,
  ios: {
    foregroundPresentationOptions: {
      alert: true,
      badge: true,
      sound: true,
    },
    critical: true,
  },
  android: {
    tag: notificationId,
    channelId,
    importance: AndroidImportance.HIGH,
    smallIcon: "ic_small_icon",
    color: "#EFC40F",
    pressAction: {
      id: "default",
    },
    sound: "default",
    style: {
      type: AndroidStyle.BIGTEXT,
      title: remoteMessage.notification?.title,
      text: remoteMessage.notification?.body ?? "",
    },
  },
})

And this is the JSON how is configured the firebase notification in the backend:

{
  "message": {
    "data": {
      "notificationId": "ae193a24-a065-4502-a408-5ce2f7351113"
    },
    "notification": {
      "title": "Title",
      "body": "Test body"
    },
    "android": {
      "priority": "high",
      "ttl": 604800000,
      "restrictedPackageName": "my.app.id",
      "collapseKey": "ae193a24-a065-4502-a408-5ce2f7351113",
      "fcmOptions": {
        "analyticsLabel": "ae193a24-a065-4502-a408-5ce2f7351113"
      },
      "notification": {
        "tag": "ae193a24-a065-4502-a408-5ce2f7351113",
        "icon": "ic_small_icon",
        "channelId": "153",
        "priority": "max",
        "sound": "default"
      }
    },
    "apns": {
      "payload": {
        "aps": {
          "contentAvailable": true,
          "sound": "default"
        }
      },
      "fcmOptions": {
        "analyticsLabel": "ae193a24-a065-4502-a408-5ce2f7351113"
      },
      "headers": {
        "apns-priority": "10",
        "apns-collapse-id": "ae193a24-a065-4502-a408-5ce2f7351113"
      }
    }
  }
}

Thank you for your assistance in resolving this matter. If further details are needed, please don't hesitate to reach out.

fgagneten avatar Feb 13 '24 20:02 fgagneten

I'm experiencing similar issues. Initially, I had problems with @react-native-firebase/messaging + react-native-push-notification. I switched to @notifee/react-native + @react-native-firebase/messaging and still encounter the same issues. Sometimes it comes through, but it can take up to 30 minutes, and in most cases, it doesn't come through at all until the app is opened.

"react": "18.2.0", "react-native": "0.72.3", "@react-native-firebase/messaging": "14.12.0", "@notifee/react-native": "^7.8.2",

iOS 17.4 (21E219), iphone 11

In the console, nothing happens, and the call to setBackgroundMessageHandler doesn't trigger.

aburduk avatar Mar 12 '24 14:03 aburduk

The issue was resolved by updating React Native from version "0.72.3" to "0.73.6".

aburduk avatar Mar 12 '24 19:03 aburduk

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Apr 09 '24 20:04 github-actions[bot]

+1

jdarshan5 avatar Apr 16 '24 16:04 jdarshan5

Is this issue resolved? I upgraded my react-native to 0.73.6 as @aburduk said, but it wasn't solved. I am trying to find many ways, Is there anyone who suffer from this problem?

hyeonseungk avatar Apr 30 '24 05:04 hyeonseungk

We still having the same issue. Didn't find any solution yet

fgagneten avatar Apr 30 '24 11:04 fgagneten

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar May 28 '24 11:05 github-actions[bot]

We also encounter this issue. We have configured a setBackgroundMessageHandler. We send a push notification with firebase admin sdk from our backend. The notification has title, body and data, content_available is true. We also have a listener for foreground push notification which looks like this:

  useEffect(() => {
    const unsubscribeFCMNotification = messaging().onMessage(message => {
      // ... some loging
      
      // display the notification
      notifee.displayNotification({
        title: message.notification?.title,
        body: message.notification?.body,
        data: message.data,
        android: {
          sound: 'ding',
          channelId: 'general',
          smallIcon: 'ic_notification',
          color: 'red'
        },
        ios: {
          sound: 'ding.wav'
        }
      })
      .catch(() => {});
      });

    return () => {
      // Clean up the event listeners
      unsubscribeFCMNotification();
    };
  }, [dispatch]);

Sending a push notification with the notification key from backend, is automatically displayed by the OS, but in some cases the same notification is passed to the messaging().onMessage listener where we display a local notification.

sanduluca avatar Jun 11 '24 14:06 sanduluca

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Jul 09 '24 14:07 github-actions[bot]

Reported the issue at react native firebase: https://github.com/invertase/react-native-firebase/issues/7836

sanduluca avatar Jul 09 '24 15:07 sanduluca

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Aug 06 '24 16:08 github-actions[bot]