How does one use the click_action property of PushNotificationSchema? I need to register that someone clicked or tapped the push notification, but this is being sent before any user action occurs.
Need to have a notification 1.) open the app 2.) send a response back to the server.
I had been using that listener and it’s not firing, though I have seen it work occasionally in the past. App is in the foreground when I tap or swipe it, nothing happens. Under what conditions should I expect that to work?
Backgrounding the app causes absolutely no relevant output in logcat. When you say local notification do you mean an AlertController? I’m using Angular.
In v4 of the Push Notification plugin, foreground notifications were added for Android (PR). I developed my app before this was changed so haven’t tested using presentationOptions.
I am not sure, it seems like it would at least show the notification when using presentationOptions per the documentation when the app is in the foreground.
From what I understand, if you aren’t using presentationOptions, then the notification won’t show up when the app is in the foreground. It only triggers pushNotificationReceived when in the foreground.
Here is my code. Like I said, I set this up before Android supported foreground push notifications so I haven’t tested with that yet.
Push notification logic
// Listens for notifications when the app is in the foreground
await PushNotifications.addListener(
'pushNotificationReceived',
async (notification: PushNotificationSchema) => {
if (!(await MyLocalNotifications.hasPermission())) {
return
}
const action = ActionNotificationItem.fromJson(notification.data)
LocalNotifications.schedule({
notifications: [
{
id: MyLocalNotifications.generateId(),
title: action.title,
body: action.body,
largeBody: action.body,
channelId: 'actions',
extra: action,
},
],
})
}
)
// Method called when tapping on a notification
await PushNotifications.addListener(
'pushNotificationActionPerformed',
(notification: ActionPerformed) => {
if (notification.actionId === 'tap') {
this.handleNavigation(
ActionNotificationItem.fromJson(notification.notification.data)
)
}
}
)