capacitor-community / fcm

Enable Firebase Cloud Messaging for Capacitor apps
https://capacitor.ionicframework.com/docs/
MIT License
237 stars 83 forks source link

TypeError: undefined is not an object (evaluating i.subscribeTo()') plugin.js: 9 #98

Open donau-software opened 2 years ago

donau-software commented 2 years ago

Describe the bug When calling fcm.subscribeTo(..) the mentioned exception is thrown, only on iOS, on Android works as expected

To Reproduce

import { FCM } from "@capacitor-community/fcm"; var fcm; try { fcm = new FCM(); } catch (e) { console.error(e); } try { PushNotifications.requestPermission().then(async (result) => { if (result.granted) { console.log("registering push notifications"); await PushNotifications.register(); } }); } catch (e) { console.error(e); } try { await fcm.subscribeTo({ topic: "all" }); <--- here it crashes if (user) { await fcm.unsubscribeFrom({ topic: "not_logged" });
await fcm.subscribeTo({ topic: "logged" }); await fcm.subscribeTo({ topic: user.uid }); } else { await fcm.subscribeTo({ topic: "not_logged" }); await fcm.unsubscribeFrom({ topic: "logged" }); } } catch (e) { console.log(fcm); console.error(e); }

From what i can see inot the source code, FCMPlugin is undefined

"@capacitor-community/fcm": "^1.1.2", "@capacitor/core": "^2.4.7", "@capacitor/ios": "^2.4.7",

Expected behavior fcm.subscribeTo({topic: "all" }) should work and subscribe user to the "all" topic

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.