Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16552

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

$
0
0

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.


Viewing all articles
Browse latest Browse all 16552

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>