Reputation: 2021
I have an issue with Push Notification for iOS in production mode.
I first developed Push for development:
All worked fine for Android as well as iOS.
I then switched to production:
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?
Upvotes: 0
Views: 198
Reputation: 2021
After contacting the Ionic Support they brought up the idea to check for the tokens being valid.
The How-To is documented in their docs:
(GET) https://api.ionic.io/push/tokens/:token_id
(where token_id
is a md5 hash of the device token)
I added a Pre-request Script in Postman for that like:
var token = "<your-device-token-to-check>";
var hash = CryptoJS.MD5( token ).toString();
postman.setEnvironmentVariable('token_hash', token);
... and added the new environment variale as a Parameter (not in the Request URL) as key: (leave empty); value: ":{{token_hash}}"
I then found out, that all my iOS tokens were invalidated shortly after they were registered. That's how our first tests succeeded and at further development suddenly failed.
I don't know why they are then left out on the response, when checking for notification status against the Ionic API. I suggested the Support to add an error response (as I understand it, there already is one: 'APNS_BAD_DEVICE_TOKEN' as "The specified device token was bad. Verify that you specified a valid token [...]".)
Because I cannot explain why, I just re-created new profiles and certificates (again!), and deleted the old ones from the Keychain Access on the Mac. I re-built the app and everything went fine. Weird...
Upvotes: 0