React-native-push-notification: onRegister fires correctly, but onNotification never catched

Created on 29 Feb 2020  路  8Comments  路  Source: zo0r/react-native-push-notification

On Android I have no problems, on iOS I am able to catch onRegister event and get the token correctly, but when I test push notifications, the event onNotification seems not working: it never fires.

My configure code is:

const configure = async () => {
    console.log('push notification configured');
    PushNotificationIOS.addEventListener('registrationError', (e) => { alert(JSON.stringify(e)) });

    PushNotification.configure({

        onRegister: function (token) {
            //process token
            alert('Token! ' + JSON.stringify(token));
            console.log('[CATCHED] onRegister:', token);
            db.setToken(token).catch(
                console.log('[ERROR] device push token has not been saved on the database'),
            );
        },

        onNotification: async function (notification) {
            console.log('[CATCHED] onNotification: ' + JSON.stringify(notification));
            let notifType = '';
            //console.log('notification received: ' + JSON.stringify(notification));
            if (Platform.OS === 'ios') {
                notifType = getNotificationType(
                    JSON.parse(notification.data.data).type,
                );
            } else {
                notifType = getNotificationType(
                    notification.type,
                );
            }
            //console.log('notification type: >>>>>>>>>>>>>>>> ' + notifType);
            //console.log('notification s: ------------------> ' + JSON.stringify(notification));
            switch (notifType) {
                {...}
            }
            // process the notification
            // required on iOS only
            if (Platform.OS === 'ios') {
                notification.finish(PushNotificationIOS.FetchResult.NoData);
            }

        },
        senderID: '-----',

        permissions: {
            alert: true,
            badge: true,
            sound: true,
        },

        popInitialNotification: true,
        requestPermissions: true,
    });
};

In iOS, the console log [CATCHED] onRegister: fires correctly, but [CATCHED] onNotification: is never fired.

Most helpful comment

same for me, onNotification only listening when clicking on the notification, but not when receiving the notification / notification fires.

All 8 comments

same for me, onNotification only listening when clicking on the notification, but not when receiving the notification / notification fires.

@strawberry-code Have you updated your AppDelegate.m ?

Still the same here. I have checked all again many times.

same here. I use AWS SNS to publish messages, on Register is fine on IOS but onNotification is never triggered. I get the push notification directly, as I use the APN certificate to create a platform application in SNS. No problem with Android. Any solution? Even if onNotification does not fire, how can I configure the style, sound, on the IOS notification?

After playing with "content-available": 1 in the payload, it worked, and onNotification fired
Screenshot 2020-04-07 at 16 38 04

Remote push notification arrives when using Knuff APN test app.
But still not working when send notifications using firebase cloud messaging function while working on android.

Hi, Can you test with the latest version of the library ?
Thanks

Issue resolved after using the latest version of this library and @react-native-community/push-notification-ios

Also added below code according to latest installation steps here

//Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
  completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}
Was this page helpful?
0 / 5 - 0 ratings