2017-07-06 4 views
0

J'essaie de construire une application android avec notification push et je veux ouvrir un composant spécifique lorsque sur une notification reçue toucher.ionique v2: Push notification pour ouvrir la page spécifique

https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/API.md

http://docs.ionic.io/services/push/

Dans mon constructeur de app.component.ts J'essaie ceci:

platform.ready().then(() => { 
     //StatusBar.styleDefault(); 
     Splashscreen.hide(); 
     this.push.rx.notification() 
      .subscribe((msg) => { 
      alert(msg.title + ': ' + msg.text); 
      console.log(msg.app, "app"); 
      console.log(msg.count, "count"); 
      console.log(msg.image, "image"); 
      console.log(msg.raw, "raw"); 
      console.log(msg.sound, "sound"); 
      console.log(msg.text, "text"); 
      console.log(msg.title, "title"); 
      }); 
    }); 

Il fonctionne bien quand mon application n'est pas près ou sur pause. Je peux voir mes journaux. Mais quand mon application est fermée ou OnPause, si je touche une notification, mon application ouverte, mais je ne peux pas avoir mes journaux.

J'ai essayé cela aussi:

this.push.on('notification', function(data) { 
     // do something with the push data 
     // then call finish to let the OS know we are done 
     this.push.finish(function() { 
     console.log("processing of push data is finished"); 
     }, function() { 
     console.log("something went wrong with push.finish for ID = " + data.additionalData.notId) 
     }, data.additionalData.notId); 
    }); 

Mais j'eu cette erreur:

Object [object Object] has no method 'on' 

Ce que je dois faire?

Répondre

0

Pour que votre événement de notification appelée lorsque votre application n'est pas au premier plan, vous devez ajouter content-available: 1 dans votre message push.

Read this link

+0

Je ne peux pas simuler cela avec firebase? https://console.firebase.google.com/ –

+0

Vous pouvez directement envoyer des messages en utilisant le protocole HTTP: [https://firebase.google.com/docs/cloud-messaging/send-message](documentatiion) – Djiggy