When receiving push in background, no events are triggered until a push notification is clicked. After it is opened, Pushwoosh plugin fires push-receive
and push-notification
events.
When a push is received in 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 foreground, e.g. update content on a current page in your app. push-notification
, on the other side, is used to react on 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 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 banner in-app alert
ALERT
– alert notification
ANDROID_FOREGROUND_PUSH
true
– do not automatically handle foreground pushes
false
– automatically handle foreground pushes (default)
Example:
cordova plugin add pushwoosh-cordova-plugin --variable IOS_FOREGROUND_ALERT_TYPE="ALERT" --variable ANDROID_FOREGROUND_PUSH="true"
To enable custom notification sound on Android, place the sound files in www/res folder and specify every sound in config.xml
:
<?xml version=‘1.0’ encoding=‘utf-8’?><widget id="YOUR_ID" version="1.0.0" xmlns="http://www.w3.org/ns/widgets” xmlns:cdv=“http://cordova.apache.org/ns/1.0">...<platform name="android"><allow-intent href="market:*" />...<-- Add this line for each sound --><resource-file src="www/res/push.wav" target="res/raw/push.wav" /></platform></widget>
The sounds will be accessible in Sound dropdown menu of Send Push panel.
On iOS, sound files are not automatically associated with Pushwoosh Application yet, but can be used manually, e.g. www/res/sound_name.wav
.
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 Icon setting in Send Push panel.
Custom push data can be sent using Action setting in the Send Push panel. To receive and handle such data use the following code:
document.addEventListener('push-notification',function(event) {var message = event.notification.message; // Push messagevar userData = event.notification.userdata; // Custom push dataif (userData) {// handle custom push data here}});
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 SDK
ERROR
– only display errors in the console
WARNING
– show warnings
INFO
– show informational messages
DEBUG
– show everything, including debug information (default)
Example:
cordova plugin add pushwoosh-cordova-plugin --variable LOG_LEVEL="INFO"
1. To enable location tracking in your application:
1.1 Install the Geozones Plugin source code into your app:
For Phonegap: phonegap plugin add pushwoosh-geozones-cordova-plugin
For Cordova: cordova plugin add pushwoosh-geozones-cordova-plugin
For Ionic: ionic plugin add pushwoosh-geozones-cordova-plugin
1.2. For iOS add the following keys to your Info.plist:
NSLocationWhenInUseUsageDescription
– (required) for app to track Geozones only while running in the foreground.
NSLocationAlwaysAndWhenInUseUsageDescription
- (required) for app to track Geozones in both conditions, and to show a permission request dialog pop-up.
NSLocationAlwaysUsageDescription
– (optional) for app to track Geozones at all times; should be used if your app targets iOS 10 and earlier versions.
On PhoneGap Build these permissions could be added using cordova-plugin-geolocation
plugin. NSLocationWhenInUseUsageDescription
can be specified using GEOLOCATION_USAGE_DESCRIPTION
variable
2. To start location tracking simply call:
var pushwooshGeozones = cordova.require("pushwoosh-geozones-cordova-plugin.PushwooshGeozones");pushwooshGeozones.startLocationTracking();
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.
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:
testBridge.callFunction('testFunction', JSON.stringify({'param1' : 1, 'param2':'test'}))
2. Add javascript interface to your project:
pushNotification.addJavaScriptInterface('testBridge');
3. Add function:
function testFunction(params) {alert("Bridge is working! " + params.param1 + " " + params.param2);}