Search code examples
iosnotificationspushadhoc

iOS Push notifications work in dev but not prod


First let me say that I've been searching to find a solution for a few hours now. I've read almost every SO question regarding this and none of the solutions have worked. I've also read the official apple docs on the subject and a few other tutorials. Basically I'm saying this to avoid the obvious suggestions like (make sure it's not "sandbox", etc).

I have both dev and prod push notification certificates for my app in the provisioning portal. I've followed the steps to create a pem file both dev and prod using apple's own documentation.

I have both dev and ad hoc distribution provisioning profiles tied to this app.

I can build my app either directly from xcode to device using the dev profile or archive it using the ad hoc distribution profile (I then use beta builder to install onto the device).

Whether I build directly with the dev profile or using the ad hoc profile (via beta builder) the push notifications work when using the sandbox + dev pem file. But as soon as I test using the prod servers + prod pem file the push notifications aren't sent.

I have two php scripts for testing, one for dev, one for prod. They are essentially identical except for the server url (sandbox vs not sandbox) and the pem file that is referenced (dev or prod).

I find it strange that even with the ad hoc build I can still send push notifications using the sandbox and dev pem, is this normal?

Is there anything else I should maybe do when going from dev to prod? I feel like I've tried everything at this point. I've re-generated the certificates and profiles many times. I follow almost the exact same procedure for generating the dev and prod pem files and my php scripts and nearly identical (for prod and dev).

I have no idea if this is a server issue or a client (app) issue? Is there a setting somewhere I may be forgetting?

I hope that someone can shed some light on this as it's starting to drive me crazy!

Cheers.


Solution

  • Well I found the problem, it was a silly mistake on my end. I'll share here in case someone else made the same mistake.

    The key thing I didn't know is that the device token is different for dev and prod (for the same device). I was using the device token I got when testing in dev to test in prod. This was working fine in dev, but when I switched to prod I kept the same device token in the php script (assuming, wrongfully, that the device token would be the same for the same device) but the actual device token registered in prod was different.

    In practice this wouldn't happen as the device token is sent to the server, but when I was testing I was using hard coded device token as I didn't want to involve the server.

    Hopefully this will save someone some frustration.