Push notification in Production mode is not coming

2019-05-31 12:45发布

问题:

My PNS is working good in development mode. I have done this using raywendelich blog. same way i have created certificates in production mode and run same script from server but not receiving any notification.

Which additional step needed when we are testing in production mode from our server.Its very urgent need. plase help what to do for production mode.

our PHP code

<?php

// Put your device token here (without spaces):
$deviceToken = 'd5d89cab86e6f1a3cfa66dd853f3f4d7dd932c4a6da793cb9c86d31e9cfcb31f';

// Put your private key's passphrase here:
$passphrase = '*******';

// Put your alert message here:
$message = '****';

 $ctx = stream_context_create();
 stream_context_set_option($ctx, 'ssl', 'local_cert', 'ckm.pem');
 stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

 // 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);

回答1:

You need to create the production APNS certificate (very similar to the way you created the developer certificate) and use that to connect to Apple instead. The development and production pushtokens are different so in order to get your production push token, you'll have to build an AdHoc version of your app. When you install the ad-hoc version on your device, it should ask you if you want to recieve push tokens. Accept and your code should send your production push token to your server (I'm assuming you save all pushtokens on a server somewhere). This is the token you need to use to test your production push code.