Push notifications - "push Notification Action Performed" listener not triggered all the times

Sometimes the “pushNotificationActionPerformed” listener it’s not triggered. When application it’s closed, after we tap on a notification, the application it’s opened and this listener works all the times. When application it’s in background and you tap on notification the listener it’s not called every time. Do you have any idea or suggestion why sometimes the listener it’s not triggered? Any help would be great. Thanks!

Where are you adding the pushNotificationActionPerformed listener and what does the code look like?

Thank you for response!

We have a service where we initiate the push notifications listeners.

import { Injectable } from "@angular/core";
import { Router } from "@angular/router";
import { ActionPerformed, PushNotificationSchema, PushNotifications,Token} from "@capacitor/push-notifications";
import { Platform } from "@ionic/angular";
import { AlertifyService } from "./alertify.service";
import { APIService } from "./api.service";
import { SharedDataService } from "./shared-data.service";

@Injectable({
  providedIn: "root",
})
export class PushNotificationService {
  constructor() {}

  initPushNotifications() {
    PushNotifications.requestPermissions().then((result) => {
      if (result.receive === "granted") {
        PushNotifications.register();
      } else {
        // Show some error
      }
    });

    PushNotifications.addListener("registration", (token: Token) => {
      if (token.value) {
        //save the token in db
        }
      }
    });

     PushNotifications.addListener("registrationError", (error: any) => {
       alert('Error on registration: ' + JSON.stringify(error));
     });

     PushNotifications.addListener(
       "pushNotificationReceived",
       (notification: PushNotificationSchema) => {
          alert('Push received: ' + JSON.stringify(notification));
       }
     );
	
     PushNotifications.addListener(
      "pushNotificationActionPerformed",
      (notification: ActionPerformed) => {
        try {
          alert('Push received: ' + JSON.stringify(notification));
        } catch (error) {
          this.alertify.errorMessage(
            "error from subscribing notification " + JSON.stringify(error)
          );
        }
      }
    );
  }
}

We call the initPushNotifications method from app.component.ts, from ngOnInit

Can you please edit your post using code blocks to make it easier to read? A code block can be created by wrapping it with three backticks (```) above and below it.

Thanks for updating the formatting!

I don’t see anything jumping out. I am not familiar with Angular so have to assume calling initPushNotifications in app.component.ts is correct.

I would try clearing the listeners before registering them. That is what I do for both push and local notifications as I was getting weird results otherwise.

Try putting the following code after requestPermissions before the first addListener.

await PushNotifications.removeAllListeners()

Ok, thank you! We will try this.

Did you find any solution? 2023 still happens in iOS.