views:

70

answers:

1

enter code hereHi guys, this problem is driving me crazy. I'm implementing APNS. I already google and followed several tutorials. I implemented the server an it seems to work find here is the code:

<?php $deviceToken = 'XXXX';

// Passphrase for the private key (ck.pem file) // $pass = '';

// Get the parameters from http get or from command line $message = $_GET['message'] or $message = $argv[1] or $message = 'Message received from javacom'; $badge = (int)$_GET['badge'] or $badge = (int)$argv[2]; $sound = $_GET['sound'] or $sound = $argv[3];

// 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', 'ck.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, 60, STREAM_CLIENT_CONNECT, $ctx); // for production change the server to ssl://gateway.push.apple.com:219 if (!$fp) { print "Failed to connect $err $errstr\n"; 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); ?>

It seems to work fine. I don't get any errors. But i don't get any push notification on my device. I don't know where the error could be. I also implemented the feedback script. No error and no output. My App is also prepared.

Thanks in advance

A: 

Apple just released a technical note titled "Troubleshooting Push Notifications". It has tips for both sending and receiving. Maybe something there can help.

Robot K
Thanks that helped me to find the Problem