iphone - Apple 推送通知服务 - 设备上没有通知

标签 iphone apple-push-notifications

这个问题快把我逼疯了。我正在实现 APNS。我已经谷歌搜索并遵循了几个教程。我实现了服务器,它似乎可以工作,这里是代码:

<?php

$deviceToken = 'XXXX';
// Passphrase for the private key (ck.pem file)
// $pass = '';
// Get the parameters from http get or from command line
$message = $_GET['message'] or $message = $argv[1] or $message = 'Message received from javacom';
$badge = (int)$_GET['badge'] 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', 'ck.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); // for production change the server to ssl://gateway.push.apple.com:219
if (!$fp) {
    print "Failed to connect $err $errstr\n";
    return;
} else {
    print "Connection OK\n";
}

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

?>

看起来效果不错。我没有收到任何错误。但我的设备上没有收到任何推送通知。我不知道错误可能出在哪里。我还实现了反馈脚本。没有错误,也没有输出。我的App也准备好了。 提前致谢。

最佳答案

Apple刚刚发布了一份名为 "Troubleshooting Push Notifications" 的技术说明。它有发送和接收的提示。也许那里有什么可以帮忙的。

关于iphone - Apple 推送通知服务 - 设备上没有通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3868274/

相关文章:

ios - CloudKit CKSubscription包括强制性通知吗?

iphone - iOS 6 上的 YouTube 播放器方向问题

ios - 如何为 uiimageview 设置动画并停止剩余进程

iphone - 用于测试的设备和 iOS 版本的最佳实践。同一台设备需要多个 iOS 版本?

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

c# - 使用 iPhone Apple 推送通知提供程序 (apns-sharp) 时出现 SslStream.AuthenticateAsClient 异常

ios - 如何从远程推送通知获取 APNS 负载?

iPhone App 无法正常复制?数据库文件仅适用于临时或应用程序商店分发且不处于开发模式

ios - 2.10 iPhone 应用程序也必须在 iPad 上运行,无需修改,iPhone 分辨率和 2X iPhone 3GS 分辨率

ios - 应用程序关闭时 didFinishLaunchingWithOptions APNS