I've been trying for days now to push notifications from my php script to my iPhone with no luck!
I've tried numerous php scripts, generating pem certificates etc!
When I run the script I get "Delivered Message to APNS" but nothing comes through to my phone.
Also I'm running this as a sandbox and my app is in development.
<?php
$tHost = 'gateway.sandbox.push.apple.com';
$tPort = 2195;
$tCert = 'push.pem';
$tPassphrase = 'password';
$tToken = 'cps2OsFjufQ:APA91xEjcjQK368UOf6XMya8huaITdl_3PrJXPB-7NQCGUu30Z7djHQPKcDCvFkMN-qLZiIA_7ZCV_cpv3zsJh5EtLJ4BpZD6mQ4B6ZYDcoLOrKLVVY67iCcS7UJ4qA2mwsvdgpJ7C6w';
$tSound = 'default';
$tPayload = 'APNS payload';
$tBody['aps'] = array(
'badge' => +1,
'alert' => 'Test notification',
'sound' => 'default'
);
$tBody ['payload'] = $tPayload;
$tBody = json_encode ($tBody);
$tContext = stream_context_create ();
stream_context_set_option ($tContext, 'ssl', 'local_cert', $tCert);
stream_context_set_option ($tContext, 'ssl', 'passphrase', $tPassphrase);
$tSocket = stream_socket_client ('ssl://'.$tHost.':'.$tPort, $error, $errstr, 30, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $tContext);
if (!$tSocket)
exit ("APNS Connection Failed: $error $errstr" . PHP_EOL);
$tMsg = chr(1) . pack('n', 32) . pack('H*', $tToken) . pack('n', strlen($tBody)) . $tBody;
$tResult = fwrite ($tSocket, $tMsg, strlen ($tMsg));
if ($tResult)
echo 'Delivered Message to APNS' . PHP_EOL;
else
echo 'Could not Deliver Message to APNS' . PHP_EOL;
fclose ($tSocket);
?>