Ios 无法连接到';ssl://gateway.sandbox.push.apple.com:2195' 从服务器端
我正在开发一款使用iOS推送通知的MAC应用程序。我想从服务器上的php脚本发送通知。我的应用程序中的代码非常适合注册远程通知并接收它们。我使用此php脚本发送通知,而且效果也很好:Ios 无法连接到';ssl://gateway.sandbox.push.apple.com:2195' 从服务器端,ios,objective-c,macos,Ios,Objective C,Macos,我正在开发一款使用iOS推送通知的MAC应用程序。我想从服务器上的php脚本发送通知。我的应用程序中的代码非常适合注册远程通知并接收它们。我使用此php脚本发送通知,而且效果也很好: <?php // My device token here (without spaces): $deviceToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // My private key's pa
<?php
// My device token here (without spaces):
$deviceToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
// My private key's passphrase here:
$passphrase = 'myPrivateKeyPassword';
// My alert message here:
$message = 'New Push Notification!';
//badge
$badge = 1;
$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,
'badge' => $badge,
'sound' => 'newMessage.wav'
);
// 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 'Error, notification not sent' . PHP_EOL;
else
echo 'notification sent!' . PHP_EOL;
// Close the connection to the server
fclose($fp);
?>
听起来好像您没有打开服务器上的端口。
请打开端口并重试
您可以通过以下命令进行验证:
$telnet gateway.sandbox.push.apple.com 2195