need help of iPhone APNS implementation

问题内容:

I am trying to implement APNS.
I test UDID and certificate with https://pushtry.com its working fine. App receive notification but not from my server. here is my server code.

// Put your private key's passphrase here:
$passphrase = 'pass_me@112';
// Put your alert message here:
$message = 'New news posted in '.$city;
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'avs_pro.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
// Create the payload body
$body['aps'] = array(
'alert' => array(
'body' => $message,
'action-loc-key' => 'AVS App',
),
'badge' => 1,
'sound' => 'default',
);

while($row = mysql_fetch_object($results))
{
// echo 'Connected to APNS' . PHP_EOL;
//iOS Notification
$deviceToken = $row->udid;
// 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)
$iPhone[] = 'Message not delivered' . PHP_EOL;
else
$iPhone[] = 'Message successfully delivered' . PHP_EOL;
}
// Close the connection to the server
fclose($fp);

问题评论:

原文地址:

https://stackoverflow.com/questions/47731684/need-help-of-iphone-apns-implementation

添加评论

友情链接:蝴蝶教程