It’s basically the same as the PHP code in the push notifications blog post.
[code]
<?php
// Put your device token here (without spaces):
$deviceToken =
'61970bfb630b0ad43b54ccd006e110d6834604b2b03df70146f03ea48fe3ac24';
// Put your private key's passphrase here:
$passphrase = 'XXXXXXX';
// Put your alert message here:
$message = 'An OSM Corona SDK push notification from ';
$message .= php\_uname('n');
echo "message: $message\n";
////////////////////////////////////////////////////////////////////////////////
$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',
'badge' =\> 4,
'custom' =\> array('anumber' =\> 1, 'aboolean' =\> true, 'astring' =\> 'stringvalue', 'afloat' =\> 3.1415),
'random' =\> 'RaNdOm',
);
// 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] [import]uid: 199237 topic\_id: 35869 reply\_id: 142940[/import]