【发布时间】:2020-12-23 12:12:05
【问题描述】:
我正在尝试让本地通知在 Ionic Vue 应用程序中工作(使用电容器)。
我确实让调度通知工作了,但现在我想听听点击通知。
在 main.js 中,我将 LocalNotifications 绑定到 this.$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 应用程序中工作通知的代码示例吗?
亲切的问候,
布拉姆
【问题讨论】:
-
你找到解决这个问题的方法了吗?
-
我最终在 main.js 中使用了这个包: import {LocalNotifications} from '@ionic-native/local-notifications' 并且在 beforeCreate 挂钩中我订阅了点击:LocalNotifications.on('click ').subscribe((x) => {...}
-
好的,谢谢您的回复!
标签: vue.js ionic-framework event-handling capacitor localnotification