Sent message to 0 ios apps 0 android apps from raix:push

159 Views Asked by At

I'm working on a Meteor+Cordova app that uses raix:push package to maintain push notifications. And I'm having a very simple config that's targeted to APNS and to development mode only, and looks like this:

{
  "apn-dev": {
    "passphrase": "qwe[]\\qwe[]\\",
    "key": "PushChatKey.pem",
    "cert": "PushChatCert.pem"
  },
  "apn": {},
  "gcm": {},
  "production": false,
  "badge": true,
  "sound": true,
  "alert": true,
  "vibrate": true
}

It refers to files PushChatKey.pem and PushChatCert.pem that are properly placed into private/ folder. The passphrase is correct.

I use a simple server-side to send push notifications:

Meteor.methods({
  sendPushNotification: function ({userId = this.userId, title = 'Hello', text = 'and welcome!'} = {}) {
    Push.send({
      title,
      text,
      from: 'push',
      badge: 14,
      query: {
        userId
      }
    });
  }
});

The problem is that, even though certificates are fine and the config is correct, the method call

Meteor.call('sendPushNotification', {}, (error, response) => console.log(error, response))

does nothing. It returns undefined, as well as both error and response are undefined (as expected). There are even some short manipulations over notification collection, an item appears and then disappears after, I believe, appropriate push notification has been sent.

The problem is, the app instance on the mobile device would never receive any of those notifications. Which may be for a reason. On the server-side log, there are messages

Settings userId "J5baP7xvbuTTX4KTk" for app: mytSJW2xrbKWRuGBZ
Send message "Hello" via query {}
Sent message "Hello" to 0 ios apps 0 android apps

So my question is, what am I doing wrong? Am I missing something in the config or in either server-side or client-side code (I don't have any of the latter that would refer to push notifications)? Has anyone hit the same roadblock? What was the solution?

1

There are 1 best solutions below

0
On

First of all, I was using wrong certificate and key, and this is directly the result of confusing Q&As and tutorials over there. I should have used certificate and private key exported from the certificate I downloaded from Apple Developer dashboard, the one that's been generated in response to my certificate request. I was using the right certificate but wrong private key. After picking the right private key, all was good, except one thing.

For some reason (and I still haven't figured out why), the app only receives the APN token from Apple after the second or third launch, i.e. not right after the user confirms receiving push notifications, but with some delay. And the Push.appCollection collection wouldn't receive an update for the corresponding entry until the app is launched again.

More than that, even the Push.appCollection collection item that represents the app on mobile device appears with some delay. But if certificates are valid, it will, guaranteed.