FCM

Improve this doc

Provides basic functionality for Firebase Cloud Messaging

Repo: https://github.com/fechanique/cordova-plugin-fcm

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-fcm
    $ npm install --save @ionic-native/fcm
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { FCM } from '@ionic-native/fcm';

constructor(private fcm: FCM) {}

...

fcm.subscribeToTopic('marketing');

fcm.getToken().then(token=>{
  backend.registerToken(token);
})

fcm.onNotification().subscribe(data=>{
  if(data.wasTapped){
    console.log("Received in background");
  } else {
    console.log("Received in foreground");
  };
})

fcm.onTokenRefresh().subscribe(token=>{
  backend.registerToken(token);
})

fcm.unsubscribeFromTopic('marketing');

Instance Members

getToken()

Get’s device’s current registration id

Returns: Promise<string> Returns a Promise that resolves with the registration id token

onTokenRefresh()

Event firing on the token refresh

Returns: Observable<string> Returns an Observable that notifies with the change of device’s registration id

subscribeToTopic(topic)

Subscribes you to a topic

Param Type Details
topic string

Topic to be subscribed to

Returns: Promise<any> Returns a promise resolving in result of subscribing to a topic

unsubscribeFromTopic(topic)

Unubscribes you from a topic

Param Type Details
topic string

Topic to be unsubscribed from

Returns: Promise<any> Returns a promise resolving in result of unsubscribing from a topic

onNotification()

Watch for incoming notifications

Returns: Observable<any> returns an object with data from the notification

NotificationData

Param Type Details
wasTapped boolean

Determines whether the notification was pressed or not

API

Native

General