React-native-push-notification: how to set notificaton badge number when app background/closed in ios

Created on 13 Sep 2018  路  3Comments  路  Source: zo0r/react-native-push-notification

it work perfectly when app foreground and not work when app background and closed.
my code:

onNotification: (notification) => {
                Device.detectNotification({"data_extra onNotification DEBUG DATA ":notification});
                if(Platform.OS === "ios")
                {
                    if(notification.message.notification_id){
                        if ( notification.foreground ){
                            // alertDropDown IOS 
                            ios_noti_data = notification.message;
                            this.dropdown.alertWithType('custom', notification.message.title, notification.message.body);
                        }
                    }

                }
                // set badge number icon app
                let notification_redux = store.getState();
                if (  Platform.OS === 'ios' ){
                    PushNotificationIOS.setApplicationIconBadgeNumber(notification_redux.notification_badge+1)
                }else{
                    RNBadgerAndroid.setBadge(notification_redux.notification_badge+1)
                }
                // count number natification unread to notification badge
                setTimeout(()=> { 
                    NotificationAPI.getNotificationUnRead()
                },1000)

                // process the notification
                // Handle When User Tap on notification forceground Android
                const clicked = notification.userInteraction;
                if (clicked ) {
                    Device.detectNotification({"data_extra userInteraction ":notification});
                    let nofify_data;
                    if (Platform.OS === "ios"){
                        nofify_data = notification.message;
                    }else{
                        nofify_data = notification;   
                    }
                    _handleNavigateScreenForSubUrl(nofify_data);
                }
                notification.finish(PushNotificationIOS.FetchResult.NoData);
            },
Stale

All 3 comments

I'm having the same issue, does anyone have an idea on this ?

Ok not obvious but eventually get to the bottom of it. look here https://github.com/zo0r/react-native-push-notification/blob/master/trouble-shooting.md you need to send silent or mixed notifications

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings