react-native-push-notification / ios

React Native Push Notification API for iOS.
MIT License
754 stars 288 forks source link

How to handle the Remote notification in foreground state ? #373

Open hardikmehta88999 opened 2 years ago

hardikmehta88999 commented 2 years ago

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.

ShubhamBathe-KM commented 2 years ago

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

//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.

Zernach commented 2 years ago

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
AnHoang13 commented 1 year ago

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