Apple Push Notifications not working in production

Push notifications do not work with my app on the App Store. With my application in development, push notifications work.

I think I should have tested through the deployment of Ad Hoc. Anyway, this is what I know ...

Application id

my app id is com.MyName.My-App

It has push notifications for development and distribution.

enter image description here

APN Certificates

I have both development and distribution certificates. This is the Dist that I care about.

enter image description here

He has the name com.MyName.My-App

Export to PEM

I selected both Cert and private key and exported it as follows:

enter image description here

and password protected it.

Then i ran

openssl pkcs12 -in Certificates.p12 -out pushcert.pem -nodes -clcerts 

providing a password and successfully receiving pushcert.pem output.

Download application

I cleared the server-side device token for my device, downloaded the application from the application store, opened it and received push notifications, and then logged into my server to check the token of my device. Now I have the token of my device. I ran this simple php script (which works when I deliver the token of my development device) but does not work with the token of my device.

 <?php // Put your device token here (without spaces): $deviceToken = 'myProductionDeviceTokenInHere'; // Put your private key passphrase here: $passphrase = 'myPasswordIsInHere'; // Put your alert message here: $message = 'Test'; //////////////////////////////////////////////////////////////////////////////// $ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushcert.pem'); stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer'); // Open a connection to the APNS server $fp = stream_socket_client( 'ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); if (!$fp) exit("Failed to connect: $err $errstr" . PHP_EOL); echo 'Connected to APNS' . PHP_EOL; // Create the payload body $body['aps'] = array( 'alert' => $message, 'sound' => 'default' ); // Encode the payload as JSON $payload = json_encode($body); // Build the binary notification $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload; // Send it to the server $result = fwrite($fp, $msg, strlen($msg)); if (!$result) echo 'Message not delivered' . PHP_EOL; else echo 'Message successfully delivered' . PHP_EOL; // Close the connection to the server fclose($fp); 

Why does he fail? It works with the token of my development device, but not with the token of my product. Didn't I do something right?

+6
source share
3 answers

What happens is that you are probably distributing with the wrong training profile. In order to receive push notifications in the final release, you need to install a new provisioning profile in which you have already enabled push notifications for distribution. This is the most common mistake, and I have encountered it once or twice in the past.

So now you have to take the following steps:

  • Sign in to the Apple Developer Center.
  • Create a new Provisioning profile for this distribution application ID Screenshot
  • Continue to install it completely, entering all the necessary data.
  • Download a profile and double-click it to install it
  • In your project, under Build Settings-> Code Signing -> Distribution select your newly created profile
  • Now Push Notifications will also reach the end user in Distribution builds.

Hope this helps, Julian.

+3
source

Make sure you are not using the sandbox certificate on the server! you have to change this to work from sandbox to prod.

0
source

Turns out this was a third-party Ruby Gem problem that I used (rpush). Not exactly what, but as soon as I switched it, everything was wonderful.

0
source

All Articles