希望在打开OneSignal推送通知时实现重定向到应用程序中的特定页面。以下是我的代码重定向到名为positions的页面,但是它似乎没有用。推送通知打开后,它仍会在InAppBrowser中打开URL。知道出了什么问题吗?预先感谢。
if (this.appConfig.Onesignal_Enable == true) {
this.oneSignal.startInit(this.appConfig.OneSignal_AppID, this.appConfig.GCM_SenderID);
this.oneSignal.handleNotificationReceived().subscribe(() => {
// do something when notification is received
});
this.oneSignal.handleNotificationOpened().subscribe((data) => {
// do something when a notification is opened
// the following two lines pass data I send with the push notification so the app knows what to open
let pushaction = data.notification.payload.additionalData.action;
let pushactionvalue = data.notification.payload.additionalData.actionvalue;
// this fires up the tab-switching
this.runNotificationAction(pushaction, pushactionvalue);
});
this.oneSignal.endInit();
}
runNotificationAction(pushaction, pushactionvalue){
// this is the data passed the the other page
let data = {"action": pushaction, "value:": pushactionvalue};
this.navCtrl.navigateForward('positions');
}
答案 0 :(得分:0)
你好,我也在使用v4 ionic,我在项目中通过此实现实现了这一点:
let self = this;
var notificationOpenedCallback = async function(jsonData) {
//I use info data previous saved, but you can use jsonData
switch (self.user.role) {
case "customer":
self.router.navigate(["history-customer"]);
break;
case "provider":
self.router.navigate(["history-provider"]);
}
};
window["plugins"].OneSignal.startInit(
"0*************7",
"1*********2"
)
.handleNotificationOpened(notificationOpenedCallback)
.endInit();
window["plugins"].OneSignal.setSubscription(true);
我用
let self = this
因为startInit会收到一个回调,所以这样做很有必要,在您的情况下,我不知道内部订阅是否也需要使用“ self”,而我使用Router来在页面之间导航。
import { Router } from "@angular/router";
在我的app-routing.module.ts
上{ path: 'history-provider', loadChildren: './pages/history-provider/history-provider.module#HistoryProviderPageModule' },
{ path: 'history-customer', loadChildren: './pages/history-customer/history-customer.module#HistoryCustomerPageModule' }