Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native-firebase: onNotificationOpenedApp and getInitialNotification not working on iOS

I'm using Cloud Messaging from react-native-firebase 7.0.1.

I do not want to store iOS device tokens in firebase, so I'm using getAPNSToken() method and then storing it on my backend.

I'm able to send notification on a device and after pressing it, the application opens.

But when I'm trying to get message from getInitialNotification() or onNotificationOpenedApp() it always returns null/undefined.

It works every time on Android.

PushHandler.js

import React from 'react';
import messaging from '@react-native-firebase/messaging';

export default class PushHandler extends React.Component {
  constructor(props) {
    super(props);
    this.messageApp = messaging();
  }

  componentDidMount() {
    this.messageApp.onNotificationOpenedApp(remoteMessage => {
      if (remoteMessage) { // <- always null on iOS
        // handle notification
      }
    });

    this.messageApp.getInitialNotification().then(initialMessage => {
      if (initialMessage) { // <- always undefined on iOS
        // handle notification
      }
    });
  }
  render() {
    return null;
  }
}
like image 718
Jakub G. Avatar asked Dec 11 '25 18:12

Jakub G.


1 Answers

Just realized that according to the docs, these functions only work when sending and receiving notifications via FCM, which is why you aren't seeing these work when sending them manually through APNS.

This package will allow for leverage getInitialNotification and the other function: https://github.com/react-native-community/push-notification-ios

like image 81
Louie Anderson Avatar answered Dec 13 '25 07:12

Louie Anderson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!