我正在尝试使本地通知在Ionic Vue应用程序中工作(使用电容器)。
我确实可以安排调度通知,但是现在我想听听对通知的点击。
在main.js中,我将LocalNotifications绑定到此。$ LocalNotifications:
import { Plugins } from '@capacitor/core';
const { LocalNotifications } = Plugins;
Vue.prototype.$LocalNotifications = LocalNotifications;
在我的根组件应用程序中,我有这个:
created() {
console.log('Created!')
document.addEventListener('deviceready', () => {
console.log('ready');
this.$LocalNotifications.addListener('localNotificationReceived', (notification) => {
console.log('Notification action received', notification);
});
}, false);
}
当我在ios-emulator上构建并运行时,我在日志中得到以下输出:
APP ACTIVE
To Native Cordova -> Badge load Badge1248600129 ["options": []]
⚡️ [log] - onscript loading complete
To Native Cordova -> Device getDeviceInfo Device1248600130 ["options": []]
⚡️ To Native -> Storage get 90127150
⚡️ TO JS {"value":null}
⚡️ [log] - Created!
To Native Cordova -> LocalNotification launch LocalNotification1248600131 ["options": []]
To Native Cordova -> LocalNotification ready INVALID ["options": []]
⚡️ To Native -> LocalNotifications addListener ⚡️ [log] - ready
90127151
⚡️ WebView loaded
⚡️ To Native -> App addListener 90127152
安排通知时,通知确实会显示,但是我认为添加监听器时有些不顺利:
INVALID ["options":[]]
有人知道如何解决吗? 还是有人在Ionic Vue应用中有工作通知的代码示例?
亲切的问候,
布拉姆