In the final stretch of understanding/implementing Ionic2 push notifications.
Last stuck on GET https://api.ionic.io/push/notifications showing my POST https://api.ionic.io/push/notifications were all of status:locked, state:enqueued, and notifications NOT showing up on device and thinking notifications were not being sent.
Quickly learned that notifications WERE being sent, it was simply that my open app was not intercepting the notifications. (Notifications fly through predictably when app was CLOSED)
From https://docs.ionic.io/services/push/ picked up on:
Handling Notifications
To handle push notifications in your app, you need to subscribe to the notification observable.
this.push.rx.notification()
.subscribe((msg) => {
alert(msg.title + ': ’ + msg.text);
});
However, I can’t get this to fire, can someone assist?
in app.ts I have:
platform.ready().then(() => {
StatusBar.styleDefault();
if (platform.is('mobileweb')) {
this.devicePushToken = { id: '', registered: false, saved: false, token: '' };
this.InitApp();
} else {
console.log('Device UUID: ' + Device.device.uuid);
let saveOptions = { ignore_user: true };
this.push.register().then((t: PushToken) => {
return this.push.saveToken(t, saveOptions);
}).then((t: PushToken) => {
this.devicePushToken = t;
console.log('Token saved:', t.token);
this.push.rx.notification()
.subscribe((msg) => {
alert(msg.title + ': ' + msg.text);
});
this.InitApp();
});
}
});