FCM

Contents

Provides basic functionality for Firebase Cloud Messaging

https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated

Ionic FCM插件的安装(Installation)

ionic cordova plugin add cordova-plugin-fcm-with-dependecy-updated npm install @ionic-native/fcm

Ionic FCM插件支持的平台(Supported Platforms)

  • Android
  • iOS

Ionic FCM插件的用法(Usage)

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

constructor(private fcm: FCM) {}

...

this.fcm.subscribeToTopic('marketing');

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

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

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

this.fcm.unsubscribeFromTopic('marketing');