【发布时间】:2021-02-15 10:44:11
【问题描述】:
我正在尝试在我的 Android 应用中使用 Capacitor FCM 插件实现通知。但是,在 Android Studio 中运行以下代码时,我收到此错误消息:“TypeError: Cannot read property 'getToken' of undefined”。
我将 Ionic 5 与 Vue 3 一起使用。
App.vue
async pushInit() {
const fcm = new FCM();
alert("...");
try {
PushNotifications.addListener("registrationError", (error) => {
console.log(`error on register ${JSON.stringify(error)}`);
}),
PushNotifications.addListener(
"pushNotificationReceived",
(notification) => {
console.log(`notification ${JSON.stringify(notification)}`);
}
),
PushNotifications.addListener(
"pushNotificationActionPerformed",
async (notification) => {
console.log("notification succeeded");
}
),
PushNotifications.register();
const fcmToken = await fcm.getToken();
alert(fcmToken);
console.log("token:" + fcmToken);
} catch (e) {
console.log(e);
}
}
我已经运行了 npx cap sync android。
【问题讨论】:
标签: firebase vue.js ionic-framework capacitor