Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Apple push notification service problem

Hi all,


I'm trying to implement notification push service to my app.

I'm reading here:

http://mobiforge.com/developing/story/programming-apple-push-notification-servic es

and here:

https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Concep tual/RemoteNotificationsPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP 40008194-CH1-SW1


When I try to connect to the sandbox service server with my php code:

[code]

<?php

$token = $_GET['myapptoken'];

$deviceToken = $token; // token dell'iPhone a cui inviare la notifica


// Passphrase for the private key (ck.pem file)

$pass = "mypass";

// Get the parameters from http get or from command line

$message = 'Notification text';

$badge = 1;

$sound = 'default';


// Construct the notification payload

$body = array();

$body['aps'] = array('alert' => $message);


if ($badge)

$body['aps']['badge'] = $badge;

if ($sound)

$body['aps']['sound'] = $sound;


/* End of Configurable Items */

$ctx = stream_context_create();

stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns-dev.pem');


// assume the private key passphase was removed.

stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);

$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 120, STREAM_CLIENT_CONNECT, $ctx);


if (!$fp) {

print "Failed to connect $err $errstrn";

return;

} else {

print "Connection OK\n";

}


$payload = json_encode($body);

$msg = chr(0).pack('n',32).pack('H*', str_replace(' ', '', $deviceToken)).pack('n',strlen($payload)).$payload;

print "sending message :" . $payload . "\n";

fwrite($fp, $msg);

fclose($fp);

?>

[/code]


I receive this message:


Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection timed out) Failed to connect 110

Posted on Nov 21, 2011 12:23 AM

Reply
Question marked as Best reply

Posted on Nov 22, 2011 11:32 PM

done!

6 replies

Apple push notification service problem

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.