单击推送通知时,未触发Ionic 6 capacitor `pushNotificationActionPerformed `事件

mhd8tkvw  于 2023-05-05  发布在  Ionic
关注(0)|答案(1)|浏览(153)

我正在我的Ionic 6应用程序中实现推送通知。我正在使用@capacitor/push-notifications插件来管理我的离子应用程序中的推送通知。

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应用程序中使用它。
请帮助,如果有人已经实现了。

0dxa2lsx

0dxa2lsx1#

我在Android中也遇到了类似的问题,能够接收推送通知,但当我们点击接收到的通知时什么也没有发生。
我通过在AndroidManifest.xml中添加下面一行解决了这个问题

<intent-filter>
      <action android:name="FCM_PLUGIN_ACTIVITY" />
      <category android:name="android.intent.category.DEFAULT" />
  </intent-filter

请在活动标签中添加以上行

相关问题