我尝试使用推送通知构建一个Android应用程序,我想在触摸收到的通知时打开一个特定的组件。
https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/API.md
http://docs.ionic.io/services/push/
在我的app.component.ts构造函数中,我试试这个:
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");
});
});
当我的应用未关闭或暂停时,它运作良好。我可以看到我的日志。 但是当我的应用程序关闭或暂停时,如果我触摸通知,我的应用程序会打开,但我无法获取我的日志。
我也试过了:
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);
});
但我有这个错误:
Object [object Object] has no method 'on'
我必须做什么?