getDeliveredNotifications()在Ionic Vue中返回一个带有电容器的空数组



我在Ionic Vue项目中使用电容器推送通知。我可以接收推送通知并单击它们,但是getDeliveredNotifications()函数返回一个空数组。推送通知正在从客户的IO发送。

下面是我的代码:
function monitorNotification() {
if (!Capacitor.isNativePlatform()) {
return;
}
PushNotifications.addListener('registration', (token: Token) => {
deviceStore.setDeviceToken(token.value);
deviceStore.saveDevice();
});
PushNotifications.addListener('registrationError', (error: any) => {
console.log('Error on registration: ' + JSON.stringify(error));
});
PushNotifications.addListener('pushNotificationActionPerformed',
(notification: ActionPerformed) => {
if (notification?.notification?.data?.message?.apns?.payload?.aps?.data?.go_to) {
router.replace({ path: notification.notification.data.message.apns.payload.aps.data.go_to })
}
else if (notification?.notification?.data?.aps?.data?.go_to) {
router.replace({ path: notification.notification.data.aps.data.go_to })
}
}
);
PushNotifications.getDeliveredNotifications().then((notifications) => {
alert('notifications:  ' + JSON.stringify(notifications)) 
// is empty array
}).catch((error) => {
console.error(error);
});

PushNotifications.addListener('pushNotificationReceived',
(notification) => {
// alert('Push received: ' + JSON.stringify(notification));
}
);
}

这可能是什么原因,我该如何解决它?我正在一台MacBook上的安卓系统上测试这款软件,方法是连接到我的手机。谢谢你。

getDeliveredNotifications()只返回那些尚未打开并且在通知中心仍然可见的通知。您的实现看起来是正确的。这取决于你什么时候调用这个方法。

获取通知屏幕上可见的通知列表。

来源

最新更新