简体   繁体   中英

Ionic v2 : Push notification to open specific page

I try to build an android App with push notification and I want to open a specific component when sur touch a received notification.

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

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

In my app.component.ts constructor I try this :

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");
          });
    });

It work well when my app isn't close or on pause. I can see my logs. But when my app is closed or onpause, if I touch notification, my app open but I can't have my logs.

I tried this too :

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);
    });

But I had this error :

Object [object Object] has no method 'on'

What I have to do ?

To have your notification event called when your application isn't in foreground, you have to add content-available: 1 into your push message.

Read this link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM