Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const options: PushOptions = {
android: {
senderID: this._platformService.FCMSenderId
},
ios: {
alert: true,
badge: true,
sound: false
},
windows: {
}
};
this.push = Push.init(options);
// Reset badge
this.push.setApplicationIconBadgeNumber(() => { }, () => { }, 0);
this.push.on('registration', (data) => {
this.sendSubscriptionToServer(data.registrationId);
});
this.push.on('notification', (data) => {
this.showPushNotification({
title: data.title,
message: data.message,
data: data.additionalData,
});
});
initPushNotification() {
if (!this.platform.is('cordova')) {
console.warn("Push notifications not initialized. Cordova is not available - Run in physical device");
return;
}
Backendless.setupDevice({
uuid: Device.uuid,
platform: Device.platform,
version: Device.version
});
let push = Push.init({
android: {
senderID: "YOUR_SENDER_ID"
},
ios: {
alert: "true",
badge: false,
sound: "true"
},
windows: {}
});
push.on('registration', (data) => {
Backendless.Messaging.registerDevice(data.registrationId).then(
function () {
alert("Registration done");
},
register() {
try {
this.pushNotification = Push.init({
ios: { alert: 'true', badge: 'true', sound: 'true' },
android: { senderID: Environment.SENDERID }
})
this.pushNotification.on('notification', (data) => {
this.events.publish('notifications:receive', data)
})
this.pushNotification.on('registration', (data) => {
this.events.publish('notifications:register', data)
})
this.pushNotification.on('error', (err) => {
console.warn('failed to initialise notifications', err.message)
})
} catch (err) {
console.warn('failed to initialise notifications', err)
}