Customizing Cordova Plugin
How to customize Pushwoosh SDK for Cordova project
Push Notifications in the Foreground
When receiving a push in the background, no events are triggered until a push notification is clicked. After it is opened, the Pushwoosh plugin fires push-receive
and push-notification
events.
When a push is received in the foreground, the plugin fires push-receive
automatically, and creates a notification in the Notification Center. When this notification is opened, it fires push-notification
.
You can listen to push-receive
event to immediately react on a push in case it is received in the foreground, e.g. update content on a current page in your app. push-notification
, on the other side, is used to react to a notification click event, which requires user interaction, e.g. to navigate within your app, trigger a new process in your app, etc.
To change the push notification foreground appearance, you can use IOS_FOREGROUND_ALERT_TYPE and ANDROID_FOREGROUND_PUSH preferences:
IOS_FOREGROUND_ALERT_TYPE
NONE
– do not display a notification when the app is in the foreground (default)BANNER
– displays a banner in-app alertALERT
– alert notification
ANDROID_FOREGROUND_PUSH
true
– do not automatically handle foreground pushesfalse
– automatically handle foreground pushes (default)
Example:
Custom Push Sound
To enable custom notification sound on Android, place the sound files in www/res folder and specify every sound in config.xml
:
The sounds will be accessible in the Sound dropdown menu of the Send Push panel.
On iOS, sound files are not automatically associated with the Pushwoosh Application yet, but can be used manually, e.g. www/res/sound_name.wav
.
Custom Push Icon
Push notification icon can be customized on Android locally by using pw_notification
as resource name for such icon (see sample 1 2); or remotely by referencing any resource name in the Icon setting in the Send Push panel.
Custom Push Data
Custom push data can be sent using the Action setting in the Send Push panel. To receive and handle such data use the following code:
Controlling Log Level
In order to assist with debugging and integration, SDK will print all the requests to the console by default. When you are ready for the production build, set LOG_LEVEL
variable to one of the following values:
NONE
– no logs from the SDKERROR
– only display errors in the consoleWARNING
– show warningsINFO
– show informational messagesDEBUG
– show everything, including debug information (default)
Example:
Deep linking
We recommend using https://github.com/EddyVerbruggen/Custom-URL-scheme It's super easy to set deep links for Cordova and it works with Pushwoosh deep linking functionality out of the box.
You can find installation and usage in this guide or in the plugin docs.
Rich Media JS Bridge
You can call your JS functions from Rich Media in Cordova WebView via javascript interfaces. A call from a Rich Media must have the following format:
<interface>.callFunction('<function_name>', <params_string>)
Example:
1. Create Rich Media with a javascript call:
2. Add a javascript interface to your project:
3. Add function:
Using Pushwoosh plugin with other FCM services
If your app uses other plugins that rely on firebase-messaging, it might result in conflicts, or in one of the plugins not working as expected. To resolve this conflict, you can add a custom FirebaseMessagingService class that will route push notifications between the plugins. Pushwoosh Cordova plugin contains a template of this class which you can use as is to force all notifications to go through Pushwoosh handlers or modify it to handle notifications from other providers as well. To enable the template, uncomment the following lines in the plugin's plugin.xml
:
Share your feedback with us
Your feedback helps us create a better experience, so we would love to hear from you if you have any issues during the SDK integration process. If you face any difficulties, please do not hesitate to share your thoughts with us via this form.
Last updated