0

I'm currently in development mode and have created all certificates for development, an app id and a certificate for the APNS. ALl have been downloaded and installed on the keychain and the .p12 has been installed in the Server.

All of the devices on the provisioning profile have the app installed and none are receiving the notification.

All ports are open and it has been also tested with a simple php app and it works, but not from the server.

What is missing?

Angie
  • 475
  • 2
  • 6
  • 20

1 Answers1

0

It's a bit vague to say that it's working with 'a simple php app'. With some more information on the difference between the flow of events on the server and the 'php app', we could probably draw some more reasonable conclusions.

Apart from that, if you haven't already, check out this great tutorial by Ali Hafizji from raywenderlich (two parts). It has a detailed explanation of pretty much everything you need, I have used it myself a couple of times(looks like it has been updated since then though). You say you are installing the .p12 on the server, while I'm pretty sure he's converting it to a .pem-file along with the private key.

Also make sure the server is using the correct tokens, as your device's token is different in development from what it is in distribution.

You should also put some health-checks server-side (in the .php or whatever you are using to establish the connection to gateway.push.apple.com) to make sure your server is actually sending anything. I.E if you're using mysql to get access to your tokens, put down a if(!$connection){die(mysql_error());} or something. This should also be done when establishing the connection to Apple. With php and stream_socket_client, you could put something like this:

$fp = stream_socket_client(
    'ssl://gateway.push.apple.com:2195', $err,
    $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);//$ctx=Stream context

if (!$fp)
    exit("Failed to connect: $err $errstr" . PHP_EOL);

And the actual pushing of the notification, or at least the php-way I've been using, fwrite() returns a boolean for wether it was successful or not, so you can do $result = fwrite($fp, $msg, strlen($msg));, and $result will be 0 if it fails.

Also make sure you're connected to the system you intend to use(sandbox or not). I might be way off here, but I think I once tried to send notifications to my device with production-profile when connecting to Apple's Sandbox-system, and didn't receive anything. You said your certificates were 'development', double-check that everything else is too.

Then again, I'm having this .php-code on my server, and I'm not completely sure what you meant by 'simple php-app works, but server doesn't'.

Sti
  • 8,275
  • 9
  • 62
  • 124
  • Thanxs this help a lot and the push notifications are now being received. – Angie Aug 21 '13 at 20:54
  • That tutorial is where I started. I am basically in this state http://stackoverflow.com/questions/11660451 and cannot get the notifications to be received. – Bruno Bronosky Sep 19 '13 at 17:55
  • @RichardBronosky Make sure you're either using development provisioning profiles and connecting to sandbox.gateway, or using distribution provisioning profiles and connecting to gateway. As far as I know, mixing those won't work (I.E connecting to sandbox with distribution profiles). And you have activated Push Notifications for the AppID in dev center? – Sti Sep 20 '13 at 00:17
  • I started over from scratch and got push notification working the first time. I never got it working on my original application that I tried to retrofit. It must have something to do with the order in which things are done. At some point I'll go and remove all the provisioning and recreate it in the order of the tutorial. – Bruno Bronosky Sep 24 '13 at 21:37
  • @RichardBronosky Actually, that's exactly what I did the first time as well. I had more mess than I could handle at the time, in the profiles and target/project. I ended up creating a fresh project to try and get Notifications working there, and it did, like you. I did not find out what I did different, so I ended up patching the original project over to this new project instead of the other way around. That can be a huge job if your original project is massive though, so you might want to try again first, yeah. Good luck! – Sti Sep 24 '13 at 22:18