Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16552

I want to do a badge increment on the main app icon while receiving a notification in inactive mode of the app

$
0
0

I am working on a chat app in react-native iOS. I want to do a badge increment on the main app icon when a notification is received, when the app is killed or force quit by the user. It works well when the app is in the background mode. But the didReceiveRemoteNotification method is not called when the app is inactive. Any idea on this? I added code inside the 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);}

Viewing all articles
Browse latest Browse all 16552

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>