Apple Production Push Service is not working!
Please, help me! I've tried intensely to find the answer to my problem but I was unsuccessful all the time.
I've implemented the Development Push Notification successfully for my app, but when submitted the app and updated the code to the Production service I can't send the push notification. I have no errors on sending at all, but the push notifications are not being received by the registered devices.
The php code for in my server is something like this:
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', 'apns-dev.pem');
$apns = stream_socket_client('ssl://gateway.push.apple.com:2195', $error, $errorString, 15, STREAM_CLIENT_CONNECT, $streamContext);
if (!$apns)
{
echo "ERROR";
} else
{
if ($error)
{
echo "ERROR: " . $error . ": " . $errorString;
}
else
{
echo "<p> Processing....</p><br />";
$inputMessage = utf8_encode($_POST['text']);
echo "<p>MESSAGE: $inputMessage</p>";
$payload['aps'] = array('alert' => $inputMessage, 'sound' => 'default');
$payload = json_encode($payload);
$apnsMessagePart1 = chr(0) . chr(0) . chr(32);
$apnsMessagePart3 = chr(0) . chr(strlen($payload)) . $payload;
$xml = simplexml_load_file("tokens.xml");
if ($xml != NULL) {
$devicesCount = 0;
foreach($xml->children() as $deviceToken)
{
echo "<p>processando aparelho com o token: $deviceToken</p>";
$apnsMessagePart2 = pack('H*', str_replace(' ', '', $deviceToken));
$apnsMessage = $apnsMessagePart1 . $apnsMessagePart2 . $ap开发者_Go百科nsMessagePart3;
$success = fwrite($apns, $apnsMessage);
if (!$success)
echo "Error sending message to $deviceToken";
else
$devicesCount++;
}
socket_close($apns);
fclose($apns);
echo "<h2>... done!</h2>";
}
else
{
echo "<h4>error: no xml file found!</h4>";
}
}
}
You can check two things
- You are using the production certificate and not development certificate
- The device tokens list doesn't have any device id which was generated by a development build. If you try to send a notification to a development device token with production certificate apple will just drop the connection silently and none of the tokens after that will receive the notifications.
精彩评论