I am new to ionic. I tried to integrate push notification in my project and it is working perfectly. I am getting notification from firebase for android and getting notification from APNS for iOS.
But I tried to track notification click action when the app is in the background or quiet state. I can able to track when my app is running in the foreground.
The below is my code. I have added this in app.component.ts
file under
platform.ready().then(() => {}
Here is my code:
var push = Push.init({
android: {
senderID: "123456789"
},
ios: {
alert: "true",
badge: true,
sound: 'true',
clearBadge: true
},
windows: {}
});
push.on('registration', (data) => {
this.clipboard.copy(data.registrationId.toString());
window.localStorage.setItem('token',data.registrationId.toString());
});
push.on('notification', (data) => {
if (data.additionalData.foreground) {
alert(data.message);
}
else if(data.additionalData.coldstart)
{
alert(data.message);
window.localStorage.setItem('pushMessage', data.message);
}
else
{
alert(data.message);
}
});
push.on('error', (e) => {
alert(e.message);
})
Whenever I try to open the app using notification click, it is not triggering the notification receive method. But if the app is open it is showing the alert.
Please help in this. Thanks in advance.