Hi,
I want to trigger pushObject.on(‘notification’) when my app is closed or is not running.
data.additionalData.foreground is work but,
data.additionalData.background and data.additionalData.coldstart is not work
Here is my “app.component.ts” code
import { Push, PushObject, PushOptions } from '@ionic-native/push/ngx';
pushObject.on('notification').subscribe(async (data: any) => {
console.log('message -> ' + data.message);
if(data.additionalData.foreground) { // if its true app is in foreground
this.router.navigateByUrl('/tabs/haber');
let alert = await this.alertCtrl.create({
header: data.title,
message: data.message,
buttons: [{
text: 'İptal',
role: 'cancel'
}, {
text: 'Aç',
handler: () => {
//TODO: Your logic here
this.router.navigateByUrl(data.message);
}
}]
});
await alert.present();
}else{ // else app is in background
console.log('onNotificationbackground');
if (data.additionalData.coldstart){
this.router.navigateByUrl('/tabs/haber');
let alerts = await this.alertCtrl.create({
header: data.title,
message: data.message + 'coldstart',
buttons: [{
text: 'İptal',
role: 'cancel'
}, {
text: 'Aç',
handler: () => {
//TODO: Your logic here
this.router.navigateByUrl('/tabs/menu');
}
}]
});
await alerts.present();
}
else if (data.additionalData.background){
this.router.navigateByUrl('/tabs/haber');
let alerts = await this.alertCtrl.create({
header: data.title,
message: data.message + 'back',
buttons: [{
text: 'İptal',
role: 'cancel'
}, {
text: 'Aç',
handler: () => {
//TODO: Your logic here
this.router.navigateByUrl(data.message);
}
}]
});
await alerts.present();
}
}
});
Please help me if you find any solution…