I created an App to send remote notifications from a web server.
When I tested the App in Development Mode all the notifications arrived correctly on the phone, after the AppStore release the app did not receive notifications anymore.
Here it is what I did:
- Created a Private Key For Production and one for development.
- Generated on my App ID two SSL Certificates by passing the previous CertFile Generated. I'm 100% sure to have generated correctly 2 key and passed them correctly to download the SSL Cert from Dev Center under AppID.
- Created a file .pem for development and one for production (by converting the file .p12 extracted from my KeyChain etc etc).
- Created 2 different provisioning profile one for development and one for production connected to the AppID of step 1.
- Signed the app in Build Settings with the correct Provisioning Profiles created in step 4.
- Created a Web App to catch and store users Tokens.
- Created a php page to test Push Notification Sending.
Here it is what i tested:
- Tested the development generated .pem file with telnet on sandbox link with a succesfull answer.
- Tested the production generated .pem file with telnet on production link with a succesfull answer.
- I'm 100% sure to have stored on my web app the development token of my iPhone.
- I'm 100% sure to have stored on my web app server the production token of my iPhone.
- I'm 100% sure to pass with my php page the right message to Apple Server (both for development and production).
- The php page always return a succesfull message from Apple Server (both for development and production).
Here is how I sign the app on Xcode:
Here is the code of the php page to send notifications:
$ctx = stream_context_create();
//stream_context_set_option($ctx, 'ssl', 'passphrase', 'development_pwd');
//stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck_development.pem');
//$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); //test
stream_context_set_option($ctx, 'ssl', 'passphrase', 'production_pwd');
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck_production.pem');
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); //production
echo "<p>Connection Open</p>";
if(!$fp){
echo "<p>Failed to connect!<br />Error Number: " . $err . " <br />Code: " . $errstrn . "</p>";
return;
} else {
echo "<p>Sending notification!</p>";
}
$i = 0;
foreach ($deviceToken as $dt) {
$dt = str_replace(' ' , '' , $dt);
$msg = chr(0) . pack('n',32) . pack('H*', $dt) . pack('n',strlen($payload)) . $payload;
echo "<p>" . $i . " - Message sent: " . $payload . "<br />Token: ". $dt . "<br />***" . $msg . "***</p>";
$result = fwrite($fp, $msg, strlen($msg));
$i++;
if (!$result)
echo '<p>Message not delivered ' . PHP_EOL . '!</p>';
else
echo '<p>Message successfully delivered ' . PHP_EOL . '!</p>';
}
fclose($fp);
echo "<p>Total Notifications Sent: " . $i . "</p>";
echo "<p>Connection Closed!</p>";
}
?>
Conclusions:
I have the Test App on my PC that receive APNS Push Notifications.
I have the exactly same app released on App Store that not receive APNS Push Notifications.
I realy made everything in my power to fix this issue and read about thousand pages of forums, stackoverflow and Apple Documentations.
I'm willing to retribuite everyone of you who helps me find the solution to my issue!
See Question&Answers more detail:
os