react-native-push-notification / ios

React Native Push Notification API for iOS.
MIT License
732 stars 281 forks source link

Handle local notification when app is in foreground #384

Open varungupta85 opened 1 year ago

varungupta85 commented 1 year ago

Currently, it shows a heads-up notification even if the app is in foreground and doesn't emit localNotification event which is not the previous behavior. Previously, no notification was shown and the localNotification event was emitted and the notification could be handled in the app as the app developer see fit.

I see that in willPresentNotification, we just call completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge); which is probably the reason a heads-up notification is shown. I tried adding [RNCPushNotificationIOS didReceiveLocalNotification:notification]; to the method and call the completionHandler using completionHandler(UNNotificationPresentationOptionNone); but I get the following error: PushNotificationiOSError

Due to my limited knowledge in Objective-C, I don't know what kind of casting is needed to cast to the right type. Please advice.

varungupta85 commented 1 year ago

I realize the issue. The notification parameter is of type UNNotification * and the method required a parameter of type UILocalNotification *. I guess we this can be fixed by either adding a converter to RCTConvert to convert UNNotification to UILocalNotification or having a method that accepts UNNotificationRequest to send events to the app.

nschild commented 11 months ago

Seeing this issue as well. Upgraded from 1.8.0 to 1.11.0. For now, we are downgrading back to 1.8.0

rakshitbharat commented 7 months ago

try to touch/tap the localNotification notification, you will get the listener triggered