HI,
is there a Plugin or hack to send a push notification to an iPhone.
I can't use the Prowl solution, because I need to implement it in our software.
I've try to put my code into the post.php in the function publish_post.
Nothing happens on the iPhone. I've use the following script:
$deviceToken = 'mydevicetoken'; // masked for security reason
// Passphrase for the private key (ck.pem file)
$pass = 'mypassword';
// Get the parameters from http get or from command line
$message = "test"; //or $message = $argv[1] or $message = ‘Message received from javacom’;
$badge = (int)1; //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', 'certs.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);
if (!$fp) {
print "Failed to connect $err $errstrn";
return;
}
else {
print "Connection OKn";
}
$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);
If I execute it on my normal apache it works.
Any ideas?
Cya,
Blacksheep