Ionic 6 电容器`pushNotificationActionPerformed`事件不会在点击推送通知时触发

问题描述 投票:0回答:0

我正在我的 Ionic 6 应用程序中实施推送通知。我正在使用

@capacitor/push-notifications
插件来管理我的 Ionic 应用程序中的推送通知。

import { Injectable } from '@angular/core';
import { Capacitor } from '@capacitor/core';
import { PushNotifications } from '@capacitor/push-notifications';

import { Router } from '@angular/router';

@Injectable({
  providedIn: 'root',
})
export class FcmService {
  constructor(private router: Router) {}

  initPush() {
    const fcmtoken = localStorage.getItem('fcmtoken');
    if (Capacitor.platform !== 'web' && !fcmtoken) {
      this.registerNotifications();
    }
  }

  registerNotifications = async () => {
    let permStatus = await PushNotifications.checkPermissions();

    if (permStatus.receive === 'prompt') {
      permStatus = await PushNotifications.requestPermissions();
    }

    if (permStatus.receive !== 'granted') {
      throw new Error('User denied permissions!');
    }

    await PushNotifications.register();

    await PushNotifications.addListener('registration', token => {
      console.info('Registration token: ', token.value);
      localStorage.setItem('fcmtoken', token.value);
    });

    await PushNotifications.addListener('registrationError', err => {
      console.error('Registration error: ', err.error);
    });

    await PushNotifications.addListener('pushNotificationReceived', notification => {
  
      console.log('Push notification received: ', notification);
    });

    await PushNotifications.addListener('pushNotificationActionPerformed', notification => {
      alert(JSON.stringify(notification));
      console.log('Push notification action performed', notification.actionId, notification.inputValue);
    });
  }

  getDeliveredNotifications = async () => {
    const notificationList = await PushNotifications.getDeliveredNotifications();
    console.log('delivered notifications', notificationList);
  }
}

我正在从 AppComponent 调用

initPush()
,我在我的应用程序中收到通知。但是,当我点击该通知时,什么也没有发生。
pushNotificationActionPerformed
事件没有被触发。我是否缺少一些配置。我在 Android 应用程序中使用它。

如果有人实施了,请帮忙。

ionic-framework push-notification ionic2 ionic3 ionic6
© www.soinside.com 2019 - 2024. All rights reserved.