Push Notification seems not to be sent (let alone received) using the Ionic API

First of all: I’m not sure if I’m correct at asking here, because it seems only questions about the framework itself are asked here, and my question is more about Ionic Cloud.



I have an issue with Push Notification for iOS in production mode.

I first developed Push for development:

  • created dev provisioning profile on Mac
  • created dev certificate on Mac
  • created a dev security profile in Ionic Dashboard
  • added dev certificate to dev security profile Ionic dashboard

All worked fine for Android as well as iOS.


I then switched to production:

  • created provisioning profile and certificate for live on Mac
  • created a live security profile in Ionic Dashboard and added live certificate


I always test Push using Postman:

send POST to https://api.ionic.io/push/notifications with body:

{
    "tokens": [
    	"<ios token>",
    	"<android token>"
    ],
    "profile": "live",
    "notification": {
        "message": "test",
	    "ios": {
		    "priority": 10
	    },
	    "android": {
		    "priority": "high"
	    }
    }
}

response:

{
  "data": {
    "status": "open",
    "config": {
      "profile": "live",
      "notification": {
        "android": {
          "priority": "high"
        },
        "ios": {
          "priority": 10
        },
        "message": "test"
      },
      "tokens": [
    	"<ios token>",
    	"<android token>"
      ]
    },
    "created": "2017-02-14T15:07:58.988762+00:00",
    "app_id": "<app id>",
    "uuid": "<uuid>",
    "state": "enqueued"
  },
  "meta": {
    "status": 201,
    "request_id": "<request id>",
    "version": "2.0.0-beta.0"
  }
}


To see what’s going on, I always send a GET afterwards to https://api.ionic.io/push/notifications/<uuid>/messages (<uuid> from the first response) and get the following response:

{
  "data": [
    {
      "status": "sent",
      "created": "2017-02-14T15:07:59.165266+00:00",
      "user_id": null,
      "token": {
        "token": "<android token>",
        "valid": true,
        "type": "android",
        "app_id": "<app id>",
        "invalidated": null,
        "id": "<id>",
        "created": "2017-02-14T14:27:27.585235+00:00"
      },
      "error": null,
      "notification": "<notification uuid>",
      "uuid": "<message uuid>"
    }
  ],
  "meta": {
    "status": 200,
    "request_id": "<request id>",
    "version": "2.0.0-beta.0"
  }
}

I noticed that the data for the corresponding <ios token> is missing in the response.
I’m wondering why there isn’t even an error response as listed at Ionic Docs.
If I send both requests using the dev security profile I get data for iOS stating “error” (APNS_BAD_DEVICE_TOKEN) - which is correct.

I already tried re-creating the certificate and stuff, which does not change the result. I also waited a whole day to receive a notification, in case something takes really long. I made double sure I built the app with the correct profiles in Xcode.

I’m using Xcode 8.2 by the way - and definetly made sure to enable “Push Notifications” in capabilities.

What am I missing?

Facing the same issue here. I also found your stackoverflow post. Did you find out why this happened?

Yes.
I later contacted official Ionic support. They told me that it seemed my tokens got invalidated and suggested to check that specific token as described in their API documentation.
And in fact my tokens got invalidated. As I remember correctly I read somewhere to make sure never mix up dev and live tokens, because when switching to production profiles Apple tends to invalidate all the tokens. So I cleared my databse of all registered devices (stored tokens) and made sure to create new ones.

They also pointed out, that I was referring to the legacy docs and that I should make shure to reference the live docs: https://docs.ionic.io/
(push documentation: https://docs.ionic.io/services/push/; and the push API docs: https://docs.ionic.io/api/endpoints/push.html)

They agreed that better error messaging would avoid trouble and questions. So maybe they implemented that as of now?

1 Like

Hi, Thanks for the quick reply. Yes, you are right, if you switch profile (dev to prod or vice versa) used in the push message, APNS does invalidate the tokens.

Created a new production push certificate and attached it to my security profile (in ioniccloud) to fix the issue.