私はPhoneGapプッシュ通知プラグインを統合しました。 Androidで通知を受け取ることができ、アプリがフォアグラウンドにあるときに特定のページを開くことができます。アプリがバックグラウンドになっている間にユーザーが通知をクリックしたときに特定のページを開きたいのですが、解決策を見つけることができません。私も下のリンクを試してみました。ここでアプリがバックグラウンドの間にIonic 3でプッシュ通知がクリックされたときに特定のページを開くにはどうすればいいですか?
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));
}
私も同じ問題に直面していますか?どのように修正されましたか? – Kittu