Push Notifications click_action called before notification actually clicked

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)
            )
        }
    }
)

Local notification logic

await LocalNotifications.addListener(
    'localNotificationActionPerformed',
    (notification: ActionPerformed) => {
        if (notification.actionId === 'tap') {
            const notificationType = notification.notification.extra?.type ?? NotificationType.None

            if (notificationType === NotificationType.Action) {
                const action = ActionNotificationItem.fromJson(
                    notification.notification.extra
                )

                MyPushNotifications.handleNavigation(action)
            }
        }
    }
)
2 Likes