I am using the latest ionic cli: 6.12.1
I am using the code for onesignal push notification:
setupPush() {
// I recommend to put these into your environment.ts
this.oneSignal.startInit('xxxxxxx-xxxxxxx-xxxxxxxx-xxxxxxx-xxxxxxxx', '11234567890');
this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.None);
// Notifcation was received in general
this.oneSignal.handleNotificationReceived().subscribe(data => {
let msg = data.payload.body;
let title = data.payload.title;
let additionalData = data.payload.additionalData;
this.showAlert(title, msg, additionalData.task);
});
// Notification was really clicked/opened
this.oneSignal.handleNotificationOpened().subscribe(data => {
// Just a note that the data is a different place here!
let additionalData = data.notification.payload.additionalData;
this.showAlert('Notification opened', 'You already read this before', additionalData.task);
});
this.oneSignal.endInit();
}
async showAlert(title, msg, task) {
const alert = await this.alertCtrl.create({
header: title,
subHeader: msg,
buttons: [
{
text: `Action: ${task}`,
handler: () => {
// E.g: Navigate to a specific screen
}
}
]
});
alert.present();
}
The message is received, when click the message, it opens the app but the alert is not shown.
Need help, thans in advance.