¿Por qué el iPhone no recibe una notificación push?

Realmente no sé dónde está el problema. Estoy utilizando la biblioteca ApnsPHP para enviar notificaciones Push. También probé otros scripts, pero eso tampoco funcionó.

Genero certificados push con este tutorial (http://code.google.com/p/apns-php/wiki/CertificateCreation) y también los pongo en el sitio web para desarrolladores de Apple. Recibo el token del iPhone que puse en sample_push.php

Tengo Macbook Pro de 13 pulgadas, mediados de 2010 con Mac OS Lion.

<code>vojta:~/dev/www/application$ php sample_push.php 
Fri, 13 Apr 2012 16:23:24 +0200 ApnsPHP[6478]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
Fri, 13 Apr 2012 16:23:32 +0200 ApnsPHP[6478]: INFO: Connected to ssl://gateway.sandbox.push.apple.com:2195.
Fri, 13 Apr 2012 16:23:32 +0200 ApnsPHP[6478]: INFO: Sending messages queue, run #1: 1 message(s) left in queue.
Fri, 13 Apr 2012 16:23:32 +0200 ApnsPHP[6478]: STATUS: Sending message ID 1 [custom identifier: Message-Badge-3] (1/3): 109 bytes.
Fri, 13 Apr 2012 16:23:33 +0200 ApnsPHP[6478]: INFO: Disconnected.
</code>

Si ejecuto "php sample_push.php" no obtendré ningún error, pero tampoco recibí ninguna notificación de inserción en mi iPhone.

Fuente sample_push.php:

<code>// Using Autoload all classes are loaded on-demand
require_once 'ApnsPHP/Autoload.php';

// Instanciate a new ApnsPHP_Push object
$push = new ApnsPHP_Push(
    ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
    'server_certificates_bundle_sandbox.pem'
);

// Set the Root Certificate Autority to verify the Apple remote peer
$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');

// Connect to the Apple Push Notification Service
$push->connect();

// Instantiate a new Message with a single recipient

$message = new ApnsPHP_Message('xxxx'); // i put my token here

// Set a custom identifier. To get back this identifier use the getCustomIdentifier() method
// over a ApnsPHP_Message object retrieved with the getErrors() message.
$message->setCustomIdentifier("Message-Badge-3");

// Set badge icon to "3"
//$message->setBadge(3);

// Set a simple welcome text
$message->setText('Hello APNs-enabled device!');

// Play the default sound
$message->setSound();

// Set the expiry value to 30 seconds
$message->setExpiry(30);

// Add the message to the message queue
$push->add($message);

// Send all messages in the message queue
$push->send();

// Disconnect from the Apple Push Notification Service
$push->disconnect();

// Examine the error message container
$aErrorQueue = $push->getErrors();
if (!empty($aErrorQueue)) {
    var_dump($aErrorQueue);
}
</code>

También estaba intentando un script mucho más simple (tampoco funciona)

<code>// Put your device token here (without spaces):
$deviceToken = 'xxxxxxxxxxx';

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

// Put your alert message here:
$message = 'My first push notification!';

////////////////////////////////////////////////////////////////////////////////

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

// Open a connection to the APNS server
$fp = stream_socket_client(
    'ssl://gateway.sandbox.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);
</code>

Realmente no sé qué hacer. Por favor ayúdame alguien.

Respuestas a la pregunta(2)

Su respuesta a la pregunta