invertase / react-native-firebase

πŸ”₯ A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.63k stars 2.2k forks source link

:fire: Data-only messages are never received on iOS #1875

Closed SchwarzerSchnee closed 5 years ago

SchwarzerSchnee commented 5 years ago

HTTP v1 POST body:

{
    "message":{
        "token":"(...)",
        "notification":{
            "body":"hello world",
            "title":"hello world",
        },
        "data":{
            "hello":"1",
            "world":"234",
        }
    }
}

Code in my app:

//This works as expected:
this.notificationListener = firebase.notifications().onNotification((notification) => {
          console.log("my data: "+JSON.stringify(notification.data));
          const { title, body } = notification;
          this.showAlert(title, body);
      });

//If I take out the notification key of the above HTTP request, I expect that this listener here should be triggered. Instead, it is never triggered at all.
this.messageListener = firebase.messaging().onMessage((message) => {
        console.log("my data: "+JSON.stringify(message));
      });

The app is running in foreground. I am finding no sources online that claim this shouldn't work.

Environment

kosintop commented 5 years ago

I also experience similar issue.

I sent a cloud message from my own server on android, onMessage is trigger on ios, onNotification is trigger instead, onMessage never trigger

shubham1164 commented 5 years ago

I can receive data only message in IOS when app is in foreground but unable to receive data only message in IOS when the app is closed and there is no info regarding the same in the docs also.

nyenye commented 5 years ago

@shubham1164 about background on iOS there is a not which specifies only Android:

https://rnfirebase.io/docs/v5.x.x/messaging/receiving-messages

on the 4rth step. Maybe its this.

For me, it happened otherwise. @kosintop, it triggered onNotifications instead of onMessage. And right now (without any apparent change, not even onMessage will trigger).

Edit: Was missing iOS authentification keys (https://firebase.google.com/docs/cloud-messaging/ios/first-message#upload_your_apns_authentication_key)

SchwarzerSchnee commented 5 years ago

In case it wasn't clear from the starting post, the issue happens on the HTTP v1 API only. It's working fine with the legacy HTTP API. We would strongly prefer not to use legacy in our project though...

shubham1164 commented 5 years ago

I am now using Voip notification for IOS and successfully able to trigger the notification on the IOS even in the closed IOS app

stale[bot] commented 5 years ago

Hello πŸ‘‹, this issue has been automatically marked as stale because it has not had activity for quite some time. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

OmarBasem commented 5 years ago

onMessage not working on ios

stale[bot] commented 5 years ago

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 the community's attention?

This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 5 years ago

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.

antseburova commented 4 years ago

onMessage is triggered on iOS on foreground only. iOS manages displaying notifications by itself when your app is on background/closed. After removing the notification object, add the following to your message object:

apns: {
        payload: {
          aps: {
            badge: unreadMessageCount,
            alert: {
              title,
              body
            }
          }
        }
}

Reference: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification

I know it is a late response, but I hope it will help somebody else who lands on this issue.