gpt4 book ai didi

ionic3 - 如何在应用程序处于后台时在 Ionic 3 中单击推送通知时打开特定页面?

转载 作者:行者123 更新时间:2023-12-05 06:37:55 24 4
gpt4 key购买 nike

我已经集成了 PhoneGap 推送通知插件。我可以在 Android 中接收通知,并且可以在应用程序位于前台时打开特定页面。当用户在应用程序处于后台时单击通知时,我想打开一个特定页面,但我找不到任何解决方案。我什至尝试了下面的链接。

https://medium.com/@ankushaggarwal/push-notifications-in-ionic-2-658461108c59

这是我的代码

initPushNotification() {
if (!this.platform.is('cordova')) {
console.warn('Push notifications not initialized. Cordova is not available - Run in physical device');
return;
}
const options: PushOptions = {
android: {
senderID: 'YOUR_SENDER_ID'
},
ios: {
alert: 'true',
badge: false,
sound: 'true'
},
windows: {}
};
const pushObject: PushObject = this.push.init(options);

pushObject.on('registration').subscribe((data: any) => {
console.log('device token -> ' + data.registrationId);
//TODO - send device token to server
});

pushObject.on('notification').subscribe((data: any) => {
console.log('message -> ' + data.message);
//if user using app and push notification comes
if (data.additionalData.foreground) {
// if application open, show popup
let confirmAlert = this.alertCtrl.create({
title: 'New Notification',
message: data.message,
buttons: [{
text: 'Ignore',
role: 'cancel'
}, {
text: 'View',
handler: () => {
//TODO: Your logic here
this.nav.push(DetailsPage, { message: data.message });
}
}]
});
confirmAlert.present();
} else {
//if user NOT using app and push notification comes
//TODO: Your logic on click of push notification directly
this.nav.push(DetailsPage, { message: data.message });
console.log('Push notification clicked');
}
});

pushObject.on('error').subscribe(error => console.error('Error with Push plugin' + error));
}

最佳答案

注入(inject)App like;

import {App } from "ionic-angular";
constructor(private app: App){...}

然后;

var nav = this.app.getActiveNav();
nav.push(DetailsPage, { message: data.message });

关于ionic3 - 如何在应用程序处于后台时在 Ionic 3 中单击推送通知时打开特定页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46962386/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com