Search code examples
iosreact-nativereact-native-firebase

Can't receive notification message from react-native-firebase in ios


So I have problems with notification messages. I successfully connected notification messages on android and have remote(data-only) messages for ios. But can't receive notification or notification plus data messages. Here is my code to catch messages:

const enabled = await firebase.messaging().hasPermission();
    if (enabled) {
        console.log('fcm enabled');

        const channel = new firebase.notifications.Android.Channel(
            'channelId',
            'Channel Name',
            firebase.notifications.Android.Importance.Max
        ).setDescription('A natural description of the channel');
        firebase.notifications().android.createChannel(channel);
        this.unsubscribeFromNotificationListener = firebase.notifications().onNotification((notification) => {
            console.log(notification);
            if (Platform.OS === 'android') {
                const localNotification = new firebase.notifications.Notification({
                    sound: 'default',
                    show_in_foreground: true,
                })
                    .setNotificationId(notification.notificationId)
                    .setTitle(notification.title)
                    .setSubtitle(notification.subtitle)
                    .setBody(notification.body)
                    .setData(notification.data)
                    .android.setChannelId('channelId')
                    .android.setColor('#000000')
                    .android.setSmallIcon(notification.android.smallIcon.icon)
                    .android.setPriority(firebase.notifications.Android.Priority.High);

                firebase.notifications()
                    .displayNotification(localNotification)
                    .catch(err => console.error(err));

            } else if (Platform.OS === 'ios') {
                console.log(notification);
                const localNotification = new firebase.notifications.Notification()
                    .setNotificationId(notification.notificationId)
                    .setTitle(notification.title)
                    .setSubtitle(notification.subtitle)
                    .setBody(notification.body)
                    .setData(notification.data)
                    .ios.setBadge(notification.ios.badge);

                firebase.notifications()
                    .displayNotification(localNotification)
                    .catch(err => console.error(err));

            }
        });
    } else {
        console.log('fcm not enabled');
    }

Solution

  • My problem was in FirebaseAppDelegateProxyEnabled flag in info.plist. It was set to NO this flag allows sending message from APNs to FCM. That's why I was able to send receive push notifications via APNs token but not via FCM token. Setting this flag to YES fixed my issue.