[SOLVED]Local notifications "Click" event with APP CLOSED


#1

Hi,
i’m using local notifications native plugin on my ionic 3 project (last versions of all), but when i click on notification and my app is closed the click event is not triggered.
It works when app is in background or foreground.

I use local notifications inside a provider and my on click code is inside its constructor but when app is closed is not work.
I’ve tried too write code inside platform ready in app/app.component.ts but not work.
This is my code:

app/app.component.ts


export class MyApp {
  @ViewChild(Nav) nav: Nav;

  rootPage: any;

  constructor(
    public platform: Platform,
    public menu: MenuController,
    public statusBar: StatusBar,
    public splashScreen: SplashScreen,
    public BeaconServiceProvider: BeaconServiceProvider, /* my provider with local notifications*/
    public RemoteServiceProvider: RemoteServiceProvider,
    public translate: TranslateService,
    public globalization: Globalization,
    private oneSignal: OneSignal,
    public ga: GoogleAnalytics
  ) {
......
}
}

my provider

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage';
import { IBeacon } from '@ionic-native/ibeacon';
import { LocalNotifications } from '@ionic-native/local-notifications';
import { RemoteServiceProvider } from '../remote-service/remote-service';
import { StorageProvider } from '../storage/storage';
import { TranslateService } from '@ngx-translate/core';
import { AlertController } from 'ionic-angular';
import { NavController, App} from "ionic-angular/index";
import { GoogleAnalytics } from '@ionic-native/google-analytics';

/*
  Generated class for the BeaconServiceProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class BeaconServiceProvider {

  remoteBeacons: Array<{major: string, minor: string}> = [];
  localBeacons: Array<{major: string, minor: string, date: any}> = [];
  bluetoothInit: boolean = false;
  private navCtrl: NavController;

  constructor(
    public http: HttpClient,
    public alertCtrl: AlertController,
    public storage: Storage,
    public ibeacon: IBeacon,
    public translate: TranslateService,
    public localNotifications: LocalNotifications,
    public RemoteServiceProvider: RemoteServiceProvider,
    public StorageProvider: StorageProvider,
    public ga: GoogleAnalytics,
    private app: App
  ) {
    console.log('Hello BeaconProvider Provider');

    this.localBeacons = this.StorageProvider.localBeacons;

    this.navCtrl = this.app.getActiveNav();

    let thiz_app = this.app;
    let remote = this.RemoteServiceProvider;
    console.log("QUI");
    this.localNotifications.on("click", function(notification, state){

      console.log("QUI2");

      this.ga.trackEvent(
        "Notifiche Beacon (" + remote.version_code + ")",
        "Apertura notifica",
        "Click sulla notifica beacon " + " {" + notification.message + "}",
        1
      );

      let nav = thiz_app.getActiveNav();
      console.log("NAV", nav);

      let data = JSON.parse(notification.data);
      let page_id = data.page_id;
      page_id = page_id.toString();

      switch(page_id)
      {
        case "" :
        case "0" :
          break;
        case "-1" : //Contact Page
            if (nav == null)
              nav.push('ContactPage');
            else if (nav.getActive().component.name != 'ContactPage')
              nav.push('ContactPage');
          break;
        default :

          remote.isPageListNew(page_id).subscribe(result => {
              let page = result.has_subpages ? 'List2Page' : 'ItemDetailsPage';

              if (nav == null)
                nav.push(page, { item: result });
              else
              {
                if( nav.getActive().component.name != page)
                  nav.push(page, { item: result });
                else
                {
                  let item_id = nav.getActive().data.item.id;
                  if (item_id != result.id)
                    nav.push(page, { item: result });
                }
              }
          });

      }

    });

  }

Any ideas why not work?
Thanks

P.S.
I’ve solved updating ionic-native components and ionic-app-scripts with the update of 12-12-2017


#2

Nothing can help me?