ios icon indicating copy to clipboard operation
ios copied to clipboard

Handle local notification when app is in foreground

Open varungupta85 opened this issue 3 years ago • 3 comments

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 avatar Nov 29 '22 11:11 varungupta85

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.

varungupta85 avatar Nov 30 '22 08:11 varungupta85

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

nschild avatar Jul 19 '23 03:07 nschild

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

rakshitbharat avatar Nov 22 '23 14:11 rakshitbharat