Push Notifications
Last updated
Was this helpful?
Last updated
Was this helpful?
Required Phonegap plugins
cordova-plugin-fcm
This plugin uses Firebase cloud messaging to send out push notifications. A server key is required from the Google Firebase Cloud Messaging Service. You can sign up for an account and acquire one here.
Follow instructions below to attain a google-services.json and/or GoogleService-Info.plist file as required by the cloud builder.
Start by first Creating a new Firebase Project
Add a new App to the project
You can add either one or more android or IOS application here. If you need push messaging for both platforms, you will need to add both versions of the application. When registering your application, make sure you use the same package ID as when you added the package to the cloud builder.
For iOS, you will also need to generate an Apple Push Notification certificate (APN) within the Certificates, Identifiers, and Profiles page. Within the FCM (Firebase console), make sure to upload those certificates as well.
Once the Apps have been registered you can get the google-services.json and GoogleService-Info.plist files. This is used in our cloud builder and sets up your app to be able to receive messages.
In order to send notifications we need to generate a private key for the service admin SDK. If you do not have a service account setup then you will need to create one first via "Manage service account permissions" link within the settings page.
Once you have downloaded the account service key json file you can add it to the /media/lib/fcm directory under Servoy solution. Name the file services.json so it can be referenced by the sendFCMPushMessage method.
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
Generate a token
Params
Function
successCallback
on success callback
Optional
Function
errorCallback
on error callback
Optional
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
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
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
To send notifications we can use scopes.phonegap.sendFCMPushMessage method. This requires adding fcm binaries from the svyphonegap releases page to /medias/lib/fcm directory. You also need to include the services.json file from above in the same directory.
Params
String
topic
Send to subscribed notification topic
Required
String
title
Notification Tile
Optional
String
body
Notification Body
Optional
String
channel
Notification Channel (ex. urgent_alert)
Optional