I am working on a chat app in react-native iOS. I want to do badge increment on main app icon when notification is received when the app is killed or force quit by user. It works well when the app is in background mode. But didReceiveRemoteNotification method is not called when the app is inactive. Any idea on this? I added code inside didReceiveRemoteNotification method of AppDelegate.
Added the following code set in AppDelegate file
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [RNNotifications didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; }- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [RNNotifications didFailToRegisterForRemoteNotificationsWithError:error]; }- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { NSLog(@"APPDELEGATE: didReceiveRemoteNotification:fetchCompletionHandler %@", userInfo); int badge = (int) application.applicationIconBadgeNumber; if ( application.applicationState == UIApplicationStateInactive ) { [[UIApplication sharedApplication] setApplicationIconBadgeNumber:badge+1]; } else if(application.applicationState == UIApplicationStateBackground) { [[UIApplication sharedApplication] setApplicationIconBadgeNumber:badge+1]; } else if(application.applicationState == UIApplicationStateActive) { [[UIApplication sharedApplication] setApplicationIconBadgeNumber:badge+1]; } completionHandler(UIBackgroundFetchResultNewData);}