ios - 音隙构建 : Not receiving ios push notifications

标签 ios cordova apple-push-notifications phonegap-build

我有一个简单的 phonegap 应用程序来测试推送通知。我使用 phonegap build 构建应用程序,然后使用 itunes 在我的 iPhone 上安装该应用程序。使用生产推送证书 pem 成功注册了推送通知。但是执行下面的php脚本后我收不到任何推送通知。脚本本身运行良好,没有任何错误。有什么想法会出错吗?

   // This this a fake device id:
$deviceToken = '9870h8v088bj29u080af894jj67klfgcv9mmm79k8e4l23456h908743n093e359';

// fake password:
$passphrase = '123456';

// Put your alert message here:
$message = 'New Message';
   ////////////////////////////////////////////////////////////////////////////////

$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' => '1'
                     );

// 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);

?>

最佳答案

我也遇到过这个问题,但是我已经找到解决方案了。要将通知发送到设备,您必须在防火墙中启用 2195 端口。只需联系您的服务器公司以启用此端口。我有来自 Hostgator 的服务器,我称他们启用了端口,现在工作正常。

关于ios - 音隙构建 : Not receiving ios push notifications,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19393254/

相关文章:

ios - 关于APNS的问题

ios - 当我在 iPad 屏幕上触摸时如何获取 PDF 注释

ios - UIWebView 中 WebSQL/SQLite 数据库的最大大小(phonegap)

javascript - 使用 PhoneGap 和 JQuery Mobile 转到下一页

java - 电话差距 [错误] cmd : Command failed with exit code ENOENT

iphone - 更改/删除远程通知上的按钮或按钮文本

iOS:在 AV 视频上绘图,然后将绘图保存在视频文件中

ios - 如何在独立的 Apple Watch 应用程序中配置推送通知

ios - 向 IOS 应用程序添加其他 Beta 测试人员

JAVAPNS 2.2 成功推送但未在设备上接收