Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to use Cordova Push Notification Plugin with Google Firebase Cloud Messaging

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 2.75k
    Comment on it

    Cordova push plugin with firebase is used to send notifications in both android and iOS devices. This plugin can be used for Cordova applications with Google Firebase FCM. You can send notifications to one or multiple devices with this plugin.



    So, in this tutorial I will guide you to "Use Cordova Push Plugin with Google Firebase Cloud Messaging".


    Let's get started:


    To install this plugin, run the following command into your cordova project:

    cordova plugin add cordova-plugin-fcm



    • Tested on Android and iOS using Cordova cli 6.4.0, Cordova android 6.0.0 and Cordova ios 4.3.1
    • 'google-services.json' and 'GoogleService-Info.plist' are required to add into your project. you can download the configuration files for Android or iOS from the Firebase Console ( Put the downloaded file in the Cordova project root folder.


    Receiving Token Refresh:

    //FCMPlugin.onTokenRefresh( onTokenRefreshCallback(token) );
    //Note that this callback will be fired everytime a new token is generated, including the first time.
      alert( token );


    Get token:

    //FCMPlugin.getToken( successCallback(token), errorCallback(err) );
    //Keep in mind the function will return null if the token has not been established yet.


    Subscribe to topic:

    //FCMPlugin.subscribeToTopic( topic, successCallback(msg), errorCallback(err) );
    //All devices are subscribed automatically to 'all' and 'ios' or 'android' topic respectively.
    //Must match the following regular expression: "[a-zA-Z0-9-_.~%]{1,900}".


    Unsubscribe from topic:

    //FCMPlugin.unsubscribeFromTopic( topic, successCallback(msg), errorCallback(err) );


    Receiving push notification data:

    //FCMPlugin.onNotification( onNotificationCallback(data), successCallback(msg), errorCallback(err) )
    //Here you define your application behaviour based on the notification data.
       //Notification was received on device tray and tapped by the user.
       alert( JSON.stringify(data) );
       //Notification was received in foreground. Maybe the user needs to be notified.
       alert( JSON.stringify(data) );


     How to use Cordova Push Notification Plugin with Google Firebase Cloud Messaging

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: