I have a problem that if a user opens the app and then press the home button or switching to another apps, and when the push notification arrives, and the user clicked on that notification, my app doesn't open. I am using this plugin in ionic -> https://ionicframework.com/docs/native/push/
It seems that when app is in background, app doesn't open when he clicked the push notification. How can I resolve that problem using that plugin.
here's my 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');
});
}
}
How can I handle or trigger this.navCtrl.push
when the user clicks on push notification when app is in background? Please help me to resolve this problem. It is almost 3 days and I can't find any solution.