One signal of additional data in ion 2/3
I am trying to work with one signal plugin in an ionic 2 app
i set one signal and it works fine.
but i dont know how to work with handleNotificationOpened function no document (i dont find anything)
I have it:
this.oneSignal.handleNotificationReceived().subscribe((msg) => {
// o something when notification is received
});
but don't know how to use msg to get data
any help? link? ... tank you
+3
source to share
1 answer
This is how I redirect the user to the linked page when I launch the app from a notification.
app.component.ts
this.oneSignal.handleNotificationOpened().subscribe((data) => {
let payload = data; // getting id and action in additionalData.
this.redirectToPage(payload);
});
redirectToPage(data) {
let type
try {
type = data.notification.payload.additionalData.type;
} catch (e) {
console.warn(e);
}
switch (type) {
case 'Followers': {
this.navController.push(UserProfilePage, { userId: data.notification.payload.additionalData.uid });
break;
} case 'comment': {
this.navController.push(CommentsPage, { id: data.notification.payload.additionalData.pid })
break;
}
}
}
+2
source to share