The setShowPushnotificationAlert method of the Pushwoosh Cordova plugin lets you display push notifications while the app is in the foreground. Pass true to show them and false to hide them.
The default depends on the plugin install variables, not on this method:
-
iOS:
IOS_FOREGROUND_ALERT_TYPEdefaults toALERT(foreground notifications are shown). Set it toNONEto hide them. -
Android:
ANDROID_FOREGROUND_PUSHdefaults totrue(foreground notifications are shown). It is written to thecom.pushwoosh.foreground_pushkey inAndroidManifest.xml.
To control foreground notifications at runtime on Android, install the plugin with ANDROID_FOREGROUND_PUSH="false"; while it is true, setShowPushnotificationAlert(false) does not hide foreground notifications. On iOS, call the method after registerDevice. See Customizing the Cordova plugin.
Example:
cordova plugin add pushwoosh-cordova-plugin --variable IOS_FOREGROUND_ALERT_TYPE="NONE" --variable ANDROID_FOREGROUND_PUSH="false"
function initPushwoosh() {
var pushwoosh = cordova.require("pushwoosh-cordova-plugin.PushNotification");
// Should be called before pushwoosh.onDeviceReady
document.addEventListener('push-notification', function(event) {
var notification = event.notification;
// Handle push open here
console.log('Received push notification: ', notification);
});
// Initialize Pushwoosh. This will trigger all pending push notifications on start.
pushwoosh.onDeviceReady({
appid: "APP_CODE"
});
// Registering for push notifications
pushwoosh.registerDevice(
function(status) {
var pushToken = status.pushToken;
console.log('Push token received: ', pushToken);
},
function(status) {
console.error('Push registration failed: ', status);
}
);
// Show notifications in the foreground
pushwoosh.setShowPushnotificationAlert(true);
}
Note: the plugin reads only appid in onDeviceReady. Older examples passed projectid and serviceName; remove both from your init code. Android FCM registration is driven by google-services.json.
The dedicated Pushwoosh Capacitor plugin has its own API; this method belongs to the Cordova plugin.
Comments
0 comments
Please sign in to leave a comment.