我遇到的问题是,如果用户打开应用程序然后按主页按钮或切换到其他应用程序,并且当推送通知到达时,并且用户点击了该通知,则我的应用程序无法打开。我在离子中使用这个插件 - > https://ionicframework.com/docs/native/push/
当app处于后台时,应用程序在点击推送通知时无法打开。如何使用该插件解决该问题。
这是我的app.component.ts
import { Component, enableProdMode } from '@angular/core';
import { Platform, NavController, App } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { Keyboard } from '@ionic-native/keyboard';
import { SplashScreen } from '@ionic-native/splash-screen';
import { HomePage } from '../pages/home/home';
import { Push, PushObject, PushOptions } from '@ionic-native/push';
import { GlobalProvider } from "./global.provider";
import { NotificationDetailsPage } from '../pages/notification-details/notification-details';
enableProdMode();
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = HomePage;
private navCtrl: any;
constructor(
private platform: Platform,
private app:App,
private statusBar: StatusBar,
private splashScreen: SplashScreen,
private keyboard: Keyboard,
private globalVar: GlobalProvider,
private push: Push
) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
this.navCtrl = this.app.getActiveNav();
this.statusBar.overlaysWebView(false);
this.statusBar.backgroundColorByHexString('#000000');
setTimeout(() => {
this.splashScreen.hide();
}, 500);
this.keyboard.disableScroll(true);
this.initPushNotification();
});
}
initPushNotification() {
const options: PushOptions = {
android: {
icon: 'small-icon',
forceShow: true
},
ios: {
alert: 'true',
badge: true,
sound: 'true'
},
windows: {}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('notification').subscribe((notification: any) => {
//Notification Display Section
this.navCtrl.push(NotificationDetailsPage, {notifyId:notification.additionalData.id});
});
pushObject.on('registration').subscribe((registration: any) => {
//Register Device ID
let platformName;
if (this.platform.is('android')) {
platformName = 'android';
} else {
platformName = 'ios';
}
this.globalVar.saveDeviceId(registration.registrationId, platformName).subscribe( data => {});
});
pushObject.on('error').subscribe(error => {
console.log('Can\'t send push notification');
});
}
}
当应用在后台时,当用户点击推送通知时,如何处理或触发this.navCtrl.push
?请帮我解决这个问题。差不多3天了,我找不到任何解决办法。