Search code examples
cordovaionic-frameworkcordova-plugin-fcm

Subscribe to topic cordova-plugin-fcm giving FCMPlugin is not defined


I want to allow user to subscribe to multiple topics via a list, So if a user select a item on list I want the user to subscribe to that topic and receive notification. Documentation says:

FCMPlugin.subscribeToTopic('topicExample');

But I get

FCMPlugin is not defined

. I am able to send notifications to default topics. I am using in Ionic V1.


Solution

  • Be sure to access the FCMPlugin object after the device-ready event:

    $ionicPlatform.ready(function() {
        FCMPlugin.subscribeToTopic('topicExample');
    });
    

    It's a bit tedious, but I tend to trace these errors by logging to console the status of the object along the flow of the program:

    console.debug('defined?: ' + typeof(FCMPlugin));
    

    For other debugging strategies see: https://stackoverflow.com/a/41744948/1786341