我正在尝试在我的 ionic 2 应用程序中使用一个信号插件
我已经安装了 Onesignal 并且工作正常,但我不知道如何使用 handleNotificationOpened
功能
根本没有文件(没有找到)
这是我的代码:
this.oneSignal.handleNotificationReceived().subscribe((msg) => {
// o something when notification is received
});
但我不知道如何使用
msg
用于获取数据。有什么帮助吗?关联?
保护你
最佳答案
这是当应用程序从通知启动时将用户重定向到相关页面的方式。
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;
}
}
}
关于ionic-framework - ionic 2/3 中的一个信号附加数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45200193/