ios icon indicating copy to clipboard operation
ios copied to clipboard

How to handle the Remote notification in foreground state ?

Open hardikmehta88999 opened this issue 3 years ago • 3 comments

Description: The push notification is coming to the real device when the app is in the foreground state but i don't know how to handle that notification in react native.

hardikmehta88999 avatar Jul 14 '22 14:07 hardikmehta88999

@hardikmehta88999 You need to add some code in your AppDelegate.m file under iOS folder:-

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... // Define UNUserNotificationCenter UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self;

    return YES; }

//Called when a notification is delivered to a foreground app. -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge); }

This is what is mentioned in the documentation , but for some reasons it’s s still not working for me.

ShubhamBathe-KM avatar Aug 23 '22 16:08 ShubhamBathe-KM

Yes, I also followed those steps in the documentation, but my app's notifications still do not appear at the top of the screen if the notification was received while the app is open in the foreground. 😪

image image

Zernach avatar Oct 26 '22 18:10 Zernach

check if onNotification return data, then based on that data you can create a local push notification

AnHoang13 avatar Nov 28 '22 02:11 AnHoang13