React-native-firebase: Notifications are only received on android but on ios Messages are received.

Created on 28 Nov 2019  路  20Comments  路  Source: invertase/react-native-firebase

Two weeks ago, remote notification were working fine on both ios and android.
Today well, on android when i send a notification, i receive a remote notification as expected.
while on ios nothing got received so i tried using onMessage method and it works only on ios which is weird . I dont know where the issue is exactly as i didn't the change the code.

componentDidMount() {
   // This code only works on android
    this.removeNotificationDisplayedListener = firebase
      .notifications()
      .onNotificationOpened(msg => {
        this.notif.localNotif(msg._body);

        console.log(msg);

        store.dispatch(addNotification());
      });

    this.removeNotificationListener = firebase
      .notifications()
      .onNotification(msg => {
        console.log(msg);
        this.notif.localNotif(msg._body);

        console.log(msg);

        store.dispatch(addNotification());
      });

   // This only works on ios and not android
    firebase.messaging().onMessage(msg => {
      console.log(msg);
      this.notif.localNotif(msg._data.Text);
    });
  }

  componentWillUnmount() {
    this.removeNotificationDisplayedListener();
    this.removeNotificationListener();
  }

"react-native": "0.59.9"
"react-native-firebase": "^5.5.6"

All 20 comments

You didn't really follow the template, so I don't know what your Pods or Android SDK versions are for firebase. Maybe those updated?

That said, for messaging items to have effective troubleshooting they need to be easily reproducible, and sending messages via the console doesn't work. Do you have a an example JSON that we could see to see what you are sending? There examples on other messaging related bugs for "push notification" "data" and "payload" as search terms I think

@mikehardy Thanks for your quick reply!

This is my pods file.

# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'

target 'lendish' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for lendish
  # Required by RNFirebase
  pod 'Firebase/Core', '~> 6.3.0'
  pod 'Firebase/Messaging', '~> 6.3.0'

  target 'lendish-tvOSTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'lendishTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

target 'lendish-tvOS' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for lendish-tvOS

end

my sdk version

ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
    }

and this is the remote message received on ios

RemoteMessage {_collapseKey: "org.reactjs.native.example.lendish", _data: {鈥, _from: "630827710601", _messageId: "-LumIfmMuur1JYDcSrl-", _messageType: undefined, 鈥
_collapseKey: "org.reactjs.native.example.lendish"
_data:
CreatedAt: "2019-11-28T13:58:54.575878343Z"
DeletedAt: ""
Description: "Notification about an activity"
DeviceToken: "nope"
DirectionID: ""
FromUserID: ""
ID: ""
NotificationType: "activity"
Read: ""
ReadTimestamp: "0001-01-01T00:00:00Z"
TargetUserID: ""
Text: "John Doe has liked your activity"
UpdatedAt: "2019-11-28T13:58:54.575878343Z"
__proto__: Object
_from: "630827710601"
_messageId: "-LumIfmMuur1JYDcSrl-"
_messageType: undefined
_sentTime: undefined
_ttl: 3600
collapseKey: (...)
data: (...)
from: (...)
messageId: (...)
messageType: (...)
sentTime: (...)
to: (...)
ttl: (...)
__proto__: Object

don't post the device token :-), I deleted it. Also Pods are ruby. 6.13.0 is current, you should try that version

I don't want to see the remote message received, I want to see the call you made to get firebase to send it. e.g. https://github.com/invertase/react-native-firebase/issues/2796#issuecomment-547580055

for completeness - I think upgrading to 6.13.0 has only a small chance of fixing it, but if you're not current we are out of luck for fixes because fixes will go on current... (also react-native is 0.59.10 on 0.59.x but also likely won't alter anything - the upgrade-helper site can show you what changed)

don't post the device token :-), I deleted it. Also Pods are ruby. 6.13.0 is current, you should try that version

I don't want to see the remote message received, I want to see the call you made to get firebase to send it. e.g. #2796 (comment)

Well its a simple api request and the back end send the notification to the device token i sent.
The problem is that the code was working great but now it doesn't,
Its most likely a new update to ios ?
I still dont the know why its behaving this way tho.

Nothing is simple with messaging.

@mikehardy is there any common causes for this ?
i have been at it for 3 days now. i uninstalled the package and reinstalled on both android and ios.
still, on notification is only triggered for android and onMessage is triggered for ios.
the certifications are ok and my xcode settings are setup exactly as the docs.

still onNotification is triggered only for android and not ios onMessage instead.

This is really weird as it was working perfectly on both platforms about 2 weeks ago.

I don't want to see the remote message received, I want to see the call you made to get firebase to send it. e.g. #2796 (comment)

I'm interested to see the actual JSON you post, in the style linked.

@mikehardy
If u mean the backend code which triggers the notification.

0555329c-bad7-4976-822f-18a98defd9c7

images of text are impossible. Text only. I have sent you a link TWICE with an example of what I want. Use it if you want my help, please.

@mikehardy ok what about this ?
when i send a test notification from firebase console to my device.
this page

Screen Shot 2019-12-01 at 5 21 59 PM

on ios device this gets sent.

RemoteMessage {_collapseKey: "bundle id", _data: {鈥, _from: "630827710601", _messageId: "-Lv11tjTv1rpHlrsQr9k", _messageType: undefined, 鈥
_collapseKey: "bundle id"
_data: {}
_from: "630827710601"
_messageId: "-Lv11tjTv1rpHlrsQr9k"
_messageType: undefined
_sentTime: undefined
_ttl: 3600
collapseKey: (...)
data: (...)
from: (...)
messageId: (...)
messageType: (...)
sentTime: (...)
to: (...)
ttl: (...)
__proto__: Object

but on android this gets received.

Notification {_body: "Hello World", _data: {鈥, _notificationId: "0:1575214009678535%4f9a1dc24f9a1dc2", _sound: "default", _subtitle: undefined, 鈥
_android: AndroidNotification
_actions: []
_autoCancel: undefined
_badgeIconType: undefined
_bigPicture: undefined
_bigText: undefined
_category: undefined
_channelId: undefined
_clickAction: undefined
_color: undefined
_colorized: undefined
_contentInfo: undefined
_defaults: undefined
_group: "campaign_collapse_key_5408369379174124621"
_groupAlertBehaviour: undefined
_groupSummary: undefined
_largeIcon: undefined
_lights: undefined
_localOnly: undefined
_notification: Notification {_body: "Hello World", _data: {鈥, _notificationId: "0:1575214009678535%4f9a1dc24f9a1dc2", _sound: "default", _subtitle: undefined, 鈥
_number: undefined
_ongoing: undefined
_onlyAlertOnce: undefined
_people: []
_priority: undefined
_progress: undefined
_remoteInputHistory: undefined
_shortcutId: undefined
_showWhen: undefined
_smallIcon: {icon: "ic_launcher"}
_sortKey: undefined
_tag: "campaign_collapse_key_5408369379174124621"
_ticker: undefined
_timeoutAfter: undefined
_usesChronometer: undefined
_vibrate: undefined
_visibility: undefined
_when: undefined
actions: (...)
autoCancel: (...)
badgeIconType: (...)
bigPicture: (...)
bigText: (...)
category: (...)
channelId: (...)
clickAction: (...)
color: (...)
colorized: (...)
contentInfo: (...)
defaults: (...)
group: (...)
groupAlertBehaviour: (...)
groupSummary: (...)
largeIcon: (...)
lights: (...)
localOnly: (...)
number: (...)
ongoing: (...)
onlyAlertOnce: (...)
people: (...)
priority: (...)
progress: (...)
remoteInputHistory: (...)
shortcutId: (...)
showWhen: (...)
smallIcon: (...)
sortKey: (...)
tag: (...)
ticker: (...)
timeoutAfter: (...)
usesChronometer: (...)
vibrate: (...)
visibility: (...)
when: (...)
__proto__: Object
_body: "Hello World"
_data: {}
_ios: IOSNotification
_attachments: []
_notification: Notification
_android: AndroidNotification {_notification: Notification, _actions: Array(0), _autoCancel: undefined, _badgeIconType: undefined, _bigPicture: undefined, 鈥
_body: "Hello World"
_data: {}
_ios: IOSNotification {_notification: Notification, _attachments: Array(0)}
_notificationId: "0:1575214009678535%4f9a1dc24f9a1dc2"
_sound: "default"
_subtitle: undefined
_title: "Lendish"
android: (...)
body: (...)
data: (...)
ios: (...)
notificationId: (...)
sound: (...)
subtitle: (...)
title: (...)
__proto__: Object
alertAction: (...)
attachments: (...)
badge: (...)
category: (...)
complete: (...)
hasAction: (...)
launchImage: (...)
threadIdentifier: (...)
__proto__: Object
_notificationId: "0:1575214009678535%4f9a1dc24f9a1dc2"
_sound: "default"
_subtitle: undefined
_title: "Lendish"
android: (...)
body: (...)
data: (...)
ios: (...)
notificationId: (...)
sound: (...)
subtitle: (...)
title: (...)
__proto__: Object

the ios log is almost completly empty however the android log has "Hello World" which i sent in the body.

what can the reason for this be ?

I don't want to see the remote message received, I want to see the call you made to get firebase to send it. e.g. #2796 (comment)

I'm interested to see the actual JSON you post, in the style linked.

@mikehardy this is the json posted from the backend.

        case notification := <-h.Notification:
            payloadJSON, err := json.Marshal(notification)
            if err != nil {
                log.Error(err)
            }
            var payload map[string]string
            json.Unmarshal(payloadJSON, &payload)
            message := messaging.Message{
                Data:  payload,
                Token: notification.DeviceToken,
                Notification: &messaging.Notification{
                    Title: "Lendish",
                    Body:  notification.Text,
                },
            }
            resp, err := h.Firebase.Send(context.Background(), &message)
            if err != nil {
                log.Error(err)
            }
            log.Info(resp)
        }
    }
}

Its written in go but its readable.

JSON

I say that because really, do you expect me to execute some Go code in order to see the actual JSON posted? You are asking random people on the internet for help but making it incredibly difficult. Make it AS EASY AS POSSIBLE if you want help, yes?

PLEASE POST THE ACTUAL JSON YOU SEND TO THE SERVER, then maybe someone can reproduce it.

@mikehardy Sorry about that... ,
Turns out there is a method called registerForRemoteNotifications();

so i added this line of code in my app.js file

componentDidMount() {
    // I Added This line.
    firebase.messaging().ios.registerForRemoteNotifications();

    this.removeNotificationDisplayedListener = firebase
      .notifications()
      .onNotificationOpened(msg => {
        console.log(msg);
        navigate('Notifications');
      });

    this.removeNotificationListener = firebase
      .notifications()
      .onNotification(msg => {
        this.notif.localNotif(msg._body);
        store.dispatch(addNotification());
        console.log(msg);
      });
  }

its abit weird since i didn't find this method in the docs but its working now !.

@blazk0 when I call ``, I get:

=================================================================
Main Thread Checker: UI API called on a background thread: -[UIApplication registerForRemoteNotifications]
PID: 2013, TID: 1479148, Thread name: (none), Queue name: com.facebook.react.RNFirebaseMessagingQueue, QoS: 0
Backtrace:
4   myapp                               0x0000000104a1cb6c -[RNFirebaseMessaging registerForRemoteNotifications:rejecter:] + 104
5   CoreFoundation                      0x00000001c02bfc10 FF63481D-FB6A-353B-B2C1-AC4EAECF594D + 1252368
6   CoreFoundation                      0x00000001c018fb00 FF63481D-FB6A-353B-B2C1-AC4EAECF594D + 6912
7   CoreFoundation                      0x00000001c01906d8 FF63481D-FB6A-353B-B2C1-AC4EAECF594D + 9944

not you ?

@zabojad i didn't get that error no

@zabojad I have same issue, did you resolve this issue?

2020-01-22 02:14:38.971929+0100 Solace[527:101424] [react-native-permissions] ios.permission.NOTIFICATIONS permission checked: granted
=================================================================
Main Thread Checker: UI API called on a background thread: -[UIApplication registerForRemoteNotifications]
PID: 527, TID: 101605, Thread name: (none), Queue name: com.facebook.react.RNFirebaseMessagingQueue, QoS: 0
Backtrace:
4   testapp                              0x0000000102311e48 -[RNFirebaseMessaging registerForRemoteNotifications:rejecter:] + 104
5   CoreFoundation                      0x000000018c86ac20 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 1252384
6   CoreFoundation                      0x000000018c73ad30 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 7472
7   CoreFoundation                      0x000000018c73b908 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 10504
8   testapp                              0x00000001024400d4 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 1896

@mikehardy Sorry about that... ,
Turns out there is a method called registerForRemoteNotifications();

so i added this line of code in my app.js file

componentDidMount() {
    // I Added This line.
    firebase.messaging().ios.registerForRemoteNotifications();

    this.removeNotificationDisplayedListener = firebase
      .notifications()
      .onNotificationOpened(msg => {
        console.log(msg);
        navigate('Notifications');
      });

    this.removeNotificationListener = firebase
      .notifications()
      .onNotification(msg => {
        this.notif.localNotif(msg._body);
        store.dispatch(addNotification());
        console.log(msg);
      });
  }

its abit weird since i didn't find this method in the docs but its working now !.

Hey did you get anything in the data object after adding this line? firebase.messaging().ios.registerForRemoteNotifications(); Because even after adding this line it returns an empty object for me.

Better if you can point me to your file which handles all

:)

Was this page helpful?
0 / 5 - 0 ratings