Firebase Messagingβ
This plugin is still in beta stage and may not work as expected. Please submit any issues to the plugin repo.
Cordova plugin for Firebase Messaging
Repo: https://github.com/chemerisuk/cordova-plugin-firebase-messaging
Installation
- Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add cordova-plugin-firebase-messaging $ npm install --save @ionic-native/firebase-messaging@4
- Add this plugin to your app's module
Supported platforms
- Android
- iOS
Usage
import { FirebaseMessaging } from '@ionic-native/firebase-messaging';
constructor(private firebaseMessaging: FirebaseMessaging) { }
...
this.firebaseMessaging.logEvent('page_view', {page: "dashboard"})
.then((res: any) => console.log(res))
.catch((error: any) => console.error(error));
Instance Members
onMessage()
Called when a push message received while app is in foreground.
Returns: Observable<any>
onBackgroundMessage()
Called when a push message received while app is in background.
Returns: Observable<any>
requestPermission()
Grant permission to recieve push notifications (will trigger prompt on iOS).
Returns: Promise<string>
getToken()
Returns a promise that fulfills with the current FCM token
Returns: Promise<string>
onTokenRefresh()
Triggers every time when FCM token updated. You should usually call getToken to get an updated token and send it to server.
Returns: Observable<void>
subscribe(topic)
Subscribe to topic in background.
Param | Type | Details |
---|---|---|
topic |
string
|
Returns: Promise<null>
IFirebaseMessage
Param | Type | Details |
---|---|---|
aps |
any
|
|
gcm |
any
|