With the release of version 8.3.23 of the Cordova plugin, we've added thesetShowPushnotificationAlert
method.
The method provides developers with the flexibility to display push notifications when the app is running in the foreground. By setting this method to either true
or false
, you can control the visibility of notifications according to your app's needs.
By default, the system's configuration for foreground notifications is set to false
, meaning notifications will not be displayed while the app is in the foreground.
To implement foreground notifications in your Cordova/Capacitor app, follow the example below::
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",
projectid: "SENDER_ID",
serviceName: "MPNS_SERVICE_NAME" // Omit this if not using MPNS
});
// Registering for push notifications
pushwoosh.registerDevice(
function(status) {
var pushToken = status.pushToken;
// Handle successful registration here
console.log('Push token received: ', pushToken);
},
function(status) {
// Handle registration error here
console.error('Push registration failed: ', status);
}
);
pushwoosh.setShowPushnotificationAlert(true);
}
Comments
0 comments
Please sign in to leave a comment.