Error: Uncaught (in promise): PushNotifications does not have web implementation

Error: Uncaught (in promise): PushNotifications does not have web implementation

如何为 web 实现捕获此异常,或如何继续为 web 推送通知。

如果有人可以帮助我,那将非常有帮助。 ☺

我实现的代码:

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

PushNotifications.addListener('pushNotificationReceived', (notification: PushNotification) => {
    console.log('Push received: ' 
        + JSON.stringify(notification.data));

    this.openToast(notification.data);
});

PushNotifications.addListener('pushNotificationActionPerformed', (notification: PushNotificationActionPerformed) => {
    console.log('Push action performed: ' 
        + JSON.stringify(notification.notification.data));

    this.navigate.navigateForward([
        'profile',
        notification.notification.data.identification,
    ]);
});

只是想知道如何在 ionic using capacitor 中为 Web 实现 PushNotification。如果有任何插件或至少我可以处理这个异常。

如果有任何进一步的说明,请告诉我

您可以在初始化推送通知之前添加此检查..

import { Capacitor } from '@capacitor/core';
     
const isPushNotificationsAvailable = Capacitor.isPluginAvailable('PushNotifications');
     
if (isPushNotificationsAvailable) {
     this.initPushNotifications();
}