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.

how to set notificaton badge number when app background/closed in ios

See original GitHub issue

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);
            },

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

4reactions
MarkRamsdencommented, Sep 28, 2018

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

0reactions
alexfovcommented, Jan 19, 2022
  1. You need @react-native-firebase/messaging
  2. use content_available: true when you send push from server
  3. Catch messages with https://rnfirebase.io/messaging/usage#background--quit-state-messages
  4. Write your badge update logic using PushNotificationIOS.setApplicationIconBadgeNumber()

Finally I managed to solve the problem/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Update badge with push notification while app in background
You have 2 ways of updating the badge count in the background. I've done this for my current app also. You don't need...
Read more >
setting badge count when app is killed - Apple Developer
Hi, I have an app that receives push notification from server with "content-available": 1. and i have set my app to increase badge...
Read more >
Troubleshooting the Badge Count - Things Support
On your iPhone or iPad, leave Things and go to the Settings app. · Tap Notifications. · Scroll down to find Things and...
Read more >
Increment iOS app's badge count in using 5 simple steps.
Step 1: Add UNNotificationServiceExtension inside the app. · Step 2: Setup App Groups. · Step 3: Setup User suit for storing badge count....
Read more >
iOS 15: How to Hide App Notification Badges on the Home ...
1. Open Control Center by swiping down diagonally from the top-right corner of the screen. 2. Tap the Focus button. 3. Tap the...
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