Push Notifications
Required Phonegap plugins
cordova-plugin-fcm
Requirements for Firebase
An Server key is required from Google Firebase Cloud Messaging Service. You can get one here. Follow instructions to attain a google-services.json file as you will need it for the build.
We may also need to update the config.xml depending on the SDK to include that resource file. You can add the following line for the Android platform: <resource-file src="google-services.json" target="google-services.json"/>
For iOS you can add a plist file with the proper values: <resource-file src="GoogleService-Info.plist"/>
For iOS, you will also need to generate an Apple Push Notification certificate (APN) within the Certificates, Identifiers, and Profiles page. Within FCM console, make sure to upload those certificates.
API Documentation
Method Summary
onTokenRefresh
Get a callback every time a token is generated, including the initial generation.
Params
Function
successCallback
on success callback
Optional
Function
errorCallback
on error callback
Optional
getToken
Generate a token
Params
Function
successCallback
on success callback
Optional
Function
errorCallback
on error callback
Optional
subscribeToTopic
Subscribe to a topic and get notifications All devices are subscribed automatically to 'all' and 'ios' or 'android' topic respectively. Topic String must match the following regular expression: "[a-zA-Z0-9-_.~%]{1,900}".
Params
Function
successCallback
on success callback
Optional
Function
errorCallback
on error callback
Optional
String
Topic
Topic to subscribe
Required
unubscribeFromTopic
unSubscribe from a topic and no longer receive notifications. All devices are subscribed automatically to 'all' and 'ios' or 'android' topic respectively. Topic String must match the following regular expression: "[a-zA-Z0-9-_.~%]{1,900}".
Params
Function
successCallback
on success callback
Optional
Function
errorCallback
on error callback
Optional
String
Topic
Topic to unsubscribe from
Required
onNotification
Define the behavior receiving a notification.
Params
Function
onNotificationCallback
when notification is received
Optional
Function
successCallback
on success callback
Optional
Function
errorCallback
on error callback
Optional
sendNotification
Send a notification to devices that are subscribed to a particular topic. An Server key is required from Google Firebase Cloud Messaging Service. You can get one here.
Params
String
authKey
FCM server key
Required
String
title
Notification Title
Required
String
body
Notification Body
Required
String
topic
send to subscribed notification topic
Optional
Function
successCallback
on success callback
Optional
Function
errorCallback
on error callback
Optional
Example Usage
Last updated