Closed jamauro closed 4 years ago
Hi,
please check this: https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/API.md#pushonnotification-callback
With activitree:push your handler looks like the following, and you were right to set in startup (Cordova side):
CordovaPush.push.on('notification', data => {
console.log('this is my message: ', data)
})
Results in this object:
I hope this answers your query, let me know otherwise. I'd also be interested in some feedback. This you find it easy to have this setup? Is the documentation clear?
Thanks for pointing me in the right direction. I'll give that a go.
The setup was more or less straightforward. I wish I had written down the areas where I got a little stuck. One thing that I had to do when upgrading was remove the package and then add it back. For some reason meteor update
didn't grab the latest.
Thanks for adding this one to the documentation!
@paulincai for some reason I can't get the console to display anything with this:
CordovaPush.push.on('notification', data => {
console.log('this is my message: ', data)
})
I took a look at the phonegap-plugin-push documentation and they mention that 'content-available': '1'
must be added in order for the push.on('notification')
handler to trigger. I tried adding it to the notification that's sent with Push.send like this:
// server side
const pushNotification = {
title: title,
body: body,
badge: badge,
userId: userId,
notId: Math.round(new Date().getTime() / 1000),
data: { path: urlPath },
'content-available': '1'
}
Push.send(pushNotification)
But this seems to prevent the push notification from being sent at all. I'm not seeing any client or server-side errors.
Is there something else that I'm missing?
Did you set this in the same startup file where you initialize Push on the client? This is a listener and would need to be started on Meteor startup (after Cordova is loaded). Pfff, right now I can’t remember whether I did the screen shot with IOS or Android, perhaps that is the Safari debugging and not Chrome which means I must have tested it on IOS ... in case this info is of any use.
Yes, your screenshot is Safari's console so it looks like you got it working on iOS :).
Here's what I have in client/startup.js
import { CordovaPush } from 'meteor/activitree:push'
Meteor.startup(function() {
if (Meteor.isCordova) {
CordovaPush.Configure({
appName: 'appname',
debug: true,
ios: {
alert: true,
badge: true,
sound: true,
clearBadge: true,
topic: 'com.xxxx.xxxx' // your IOS app id.
}
});
CordovaPush.push.on('notification', data => {
console.log("notification: ", data);
}
});
Thanks for the v2 update! I was able to put a urlPath that I want to route to when the user clicks on the push notification in
data
but I'm not sure how to read that urlPath and let my router handle it.Can you point me in the right direction?
Here's what I have in
client/startup.js