I'm looking reset application badge number in react-native-push-notification when the user opens the app but can't find the method anywhere in the docs, any idea?
Asked
Active
Viewed 1.2k times
4
-
2try `setApplicationIconBadgeNumber(0)` , reference: https://facebook.github.io/react-native/docs/pushnotificationios.html#setapplicationiconbadgenumber – Ivan Chernykh Feb 25 '18 at 12:23
3 Answers
7
https://facebook.github.io/react-native/docs/pushnotificationios.html#setapplicationiconbadgenumber
PushNotificationIOS.getApplicationIconBadgeNumber((num)=>{ // get current number
if(num >= 1){
PushNotificationIOS.setApplicationIconBadgeNumber(0) //set number to 0
}
});
PushNotificationIOS
imported from react native

Liam
- 6,517
- 7
- 25
- 47
5
You can add this to your AppDelegate.m, which will set badge count to 0 when app is opened or goes into the background.
- (void)applicationDidBecomeActive:(UIApplication *)application{
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}
-(void)applicationDidEnterBackground:(UIApplication *)application{
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}
Or
Within app.js (if using react hooks), will also reset badge count when app becomes active or goes into background
import { AppState } from 'react-native';
useEffect(() => {
AppState.addEventListener("change", _handleAppStateChange);
return () => {
AppState.removeEventListener("change", _handleAppStateChange);
};
}, []);
const _handleAppStateChange = (nextAppState) => {
if (Platform.OS === 'ios' && nextAppState === 'active' || nextAppState === 'background') {
PushNotificationIOS.setApplicationIconBadgeNumber(0);
}
}

Dylan w
- 2,565
- 1
- 18
- 30
1
Very Simple
import PushNotification from 'react-native-push-notification';
...
...
PushNotification.setApplicationIconBadgeNumber(0); //magic

Pradeep Kumar
- 11
- 4