d11wtq
d11wtq

Reputation: 35308

Apple Push Notification Not Arriving on Test Device

I've followed Apple's documentation.

Inside my application I successfully register for notifications (alerts, badges and sounds) and send the device token to my server (it's a 32 byte string, which I encode hexadecimally for transport and storage). This all works.

As stated in the docs, my provisioning profile contains 'aps-environment' set to 'development'. I have generated a PEM file from both the certificate and the key associated with this certificate.

I'm using Grocer (on Github) to send the notification from my server. Apple happily accepts the notification, but it never arrives on the device. I've tried numerous times in the past 12 hours, making sure the app is not running in the foreground. I'm using gateway.sandbox.push.apple.com as the endpoint.

I'm at a loss. What should I look at? Apple's own Troubleshooting Guide didn't help me.

Some people have mentioned generating an Ad-Hoc provisioning profile (though Apple doesn't state this is needed). I tried it anyway, but the profile then say "production" under aps-environment and I cannot install my application on my device.

EDIT | I can only assume I have the PEM certificate set up incorrectly... I say this because grocer still appears to 'send' the notification even if I use some completely random certificate. Not sure how to debug any errors.

Upvotes: 2

Views: 2078

Answers (2)

d11wtq
d11wtq

Reputation: 35308

It turned out that this was just me hex-encoding the device token incorrectly on the client side. I was effectively do this:

char *buf = malloc(sizeof(char) * 2 * numBytes);

while (numBytes--)
  sprintf(buf+=2, "%02x", *(bytes++));

The problem was that bytes was a char*, when it should have been a unsigned char*, so the data was getting corrupted.

Upvotes: 0

Chakalaka
Chakalaka

Reputation: 2827

you need the sandbox gateway when you use the developer profile:

gateway.sandbox.push.apple.com

if this still dont work, try reboot the device! this often helps!

dont forget to change the link when your app is released!

Upvotes: 2

Related Questions