Ionic Push APNS error phonegap-plugin-push

I have push running flawlessly for Android, but when I try to run the exact same curl command I’m using for Android with an iOS token, notifications don’t go through and when I check the message status I see:

{“error”: {“message”: “Attempted to connect to the API via HTTP, but HTTPS is required.”, “link”: null, “type”: “ProtocolError”}, “meta”: {“version”: “2.0.0-beta.0”, “status”: 400, “request_id”: “3bfbfad0-12b8-44a5-ab5e-3ca3dde120a8”}}

What gives? I have my certificate uploaded, I followed the tutorials step by step and it is working on Android. Any ideas how to fix this?

This is the curl command I’m using to test:

curl -X POST -H “Authorization: Bearer my_api_token” -H “Content-Type: application/json” -d ‘{
“tokens”: [“device_token”],
“profile”: “first_try”,
“notification”: {
“message”: “Alert!”
}
}’ “https://api.ionic.io/push/notifications

Anyone? This error is not mentioned in the docs and I’m not sure what to take from it! The initial response says the message is queued. Is this a problem communicating with the Apple Push Server??

Try using this third party app to push a notification to iOS first, it will help you rule out device issues. If your notification is getting delivered to device from Pusher that means everything on the device side is fine and there is an Ionic setup issue.

You just have to upload your .p12 file and give the device token

It works fine with that plugin. I upload the exact same certificate to ionic.io push services and still see the 400 error when I check message status sent to ios devices. When I send out a push to all devices via the dashboard, only android devices receive it.

I had the exact same problem. Is this a dev build from xcode or is it being downloaded from App Store?

If you are testing your app on IOS using Xcode, then make sure that the security profile on Ionic dashboard is of type development and not production.

Create a separate profile with type development and upload the same .p12 file there and send push using this profile.

It is a dev build and I am using a dev certificate as well as a development security profile. This is incredibly frustrating. I can’t understand why the plugin mentioned above would function properly with the exact same p12 file, but ionic.io fails.

Then you will have to see what the error code for the message is.

Curl a notification to your IOS device and then check the status using

curl -X GET -H “Authorization: Bearer YOUR API KEY” -H “Content-Type: application/json” -d ‘’ “https://api.ionic.io/push/notifications/UUID/messages”

I am not sure if you have noticed but apparently a notification is different from a message. I think message is the content of the notification and this what you have to track. So once you curl the notification, the “notification” should get enqueued (this just says IONIC might process it). After this you will get the UUID of this notification, use the UUID in the above request to check the status of the message.

Thank you for your help. Now I am seeing, “ILLEGAL_CREDENTIAL_FORMAT” but how can this be if the exact same certificate is working in the other application?

Again, are you sure the Security Profile on Ionic Dashboard is set to Development? Just try creating another one as development and add the .p12 there and test.

If that doesn’t work you will have create another Development SSL .cer from your APP ID screen on apple site and then create a new provisioning profile (so that the new cert is also included). Test with Pusher first with the new .p12 and then upload this to the Dev profile on IONIC and try again.

Note - You cannot simply export a new .p12 with a different password. Doesn’t work. Also having two dev SSL .cers doesn’t cause problems as long as you regenerate a new provisioning profile

1 Like

Okay, that finally got it working. I had to regenerate my provisioning profile for the new SSL. Thanks so much for your help, I really would not have figured that out. God I wish iOS was as easy as Android.

1 Like

I had the same issue and it was a typo (copy/paste with a break line just after the api_token)

curl -X POST -H "Authorization: Bearer my_api_token
" -H "Content-Type: application/json" -d '{
"tokens": ["device_token"],
"profile": "first_try",
"notification": {
"message": "Alert!"
}
}' "https://api.ionic.io/push/notifications"

fails with Attempted to connect to the API via HTTP, but HTTPS is required

curl -X POST -H "Authorization: Bearer my_api_token" -H "Content-Type: application/json" -d '{
"tokens": ["device_token"],
"profile": "first_try",
"notification": {
"message": "Alert!"
}
}' "https://api.ionic.io/push/notifications"

works fine

1 Like