Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS push notification show up sometimes after opening the app #990

Closed
fgagneten opened this issue Feb 13, 2024 · 11 comments
Closed

iOS push notification show up sometimes after opening the app #990

fgagneten opened this issue Feb 13, 2024 · 11 comments

Comments

@fgagneten
Copy link

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.

@aburduk
Copy link

aburduk commented Mar 12, 2024

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
Copy link

aburduk commented Mar 12, 2024

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

Copy link

github-actions bot commented Apr 9, 2024

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.

@jdarshan5
Copy link

+1

@hyeonseungk
Copy link

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?

@fgagneten
Copy link
Author

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

Copy link

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.

@sanduluca
Copy link
Contributor

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.

Copy link

github-actions bot commented Jul 9, 2024

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.

@sanduluca
Copy link
Contributor

Reported the issue at react native firebase: invertase/react-native-firebase#7836

Copy link

github-actions bot commented Aug 6, 2024

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 github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants