question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onRegister fires correctly, but onNotification never catched

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:8

github_iconTop GitHub Comments

3reactions
omerkhan8commented, Mar 1, 2020

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

0reactions
pakshucommented, May 6, 2020

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);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

react-native-push-notification onRegister fires correctly, but ...
On Android I have no problems, on iOS I am able to catch onRegister event and get the token correctly, but when I...
Read more >
DocuPrint 5105 d User Guide - FUJIFILM Business Innovation
Never attempt any procedure on the machine that is not specifically described in this manual. ... catch fire and cause burn injuries or...
Read more >
Health and Safety Policy - LCB Group
The Management of Health and Safety at Work Regulations (Regulation 5) requires the employer to have arrangements in place to cover health and...
Read more >
Changelog - LTTng
[hc] * Fix: rotation may never complete in per-PID buffering mode * Fix: perform local data pending before checking data pending with relayd...
Read more >
matrix-react-sdk | Yarn - Package Manager
This is a react-based SDK for inserting a Matrix chat/voip client into a web page. This package provides the React components needed to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found