Can't get notification response for push notifications on iOS
See original GitHub issueWe are using the LocalNotification plugin for local notifications in our app, and it works great! We are also using Firebase push notifications, and now we are implementing support for performing different actions in the app when the user taps different push notifications.
To achieve this, we have implemented DidReceiveNotificationResponse()
in our AppDelegate
and use data in response.Notification.Request.Content.UserInfo
to know which notification type the user has tapped. The problem is that our implementation of DidReceiveNotificationResponse()
never gets called when the LocalNotification plugin is enabled. I suspect the reason is that the plugin also implements this method.
We have also tried to use the NotificationTapped
event from the LocalNotification plugin. This event does get called when the user taps the push notification, however, the Request
member of the NotificationEventArgs
parameter is null
, so there is no way for us to know which push notification that was tapped.
Is there any way we can get our implementation of DidReceiveNotificationResponse()
to be called when using the plugin? Or would it be possible to update the plugin to pass the Content
or UserInfo
data from the push notification in the NotificationTapped
event? Or do you have any other suggestions on how to solve this?
Note: This is only a problem for us on iOS. On Android, we get the data we need in MainActivity.OnNewIntent()
when the user taps a push notification.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (5 by maintainers)
@thudugala Sorry for the delay. I have now tested the latest version (v10.0.2) and it works well! I can get my push notifications and the local notifications are handled correctly by the plugin.
I don’t know why it didn’t work on 9.2.1-preview01, but it may very well have been an error in my code.
Thanks for your support and your patience 😃
I have managed to implement a workaround that allows my implementation of
DidReceiveNotificationResponse()
to get called and still use the LocalNotification plugin as intended. Maybe it can be useful for someone else that uses both push and local notifications.Step 1: Initialize the LocalNotification plugin before assigning my own UNUserNotificationCenter delegate. Step 2: Save a reference to the plugin’s UNUserNotificationCenter delegate. Step 3: Assign my own UNUserNotificationCenter delegate. Step 4: In my implementation of
WillPresentNotification()
andDidReceiveNotificationResponse()
, I handle my push notifications and also forward the call to the plugin’s delegate I stored earlier, so it can handle local notifications.Code snippets from my AppDelegate:
@thudugala, any thoughts? Maybe a future version of the plugin could accept a UNUserNotificationCenter delegate parameter somewhere. I could then pass my AppDelegate to the plugin and it could forward any calls it can’t handle to me.