【发布时间】:2013-03-18 12:41:30
【问题描述】:
我为 ios 开发了一个应用程序,它已在应用程序商店上发布。 推送通知系统在开发中运行良好,但现在,我根本没有收到任何通知。 在发布之前,我已经生成了与启用推送并配置了生产推送 SSL 证书的应用程序 ID 关联的开发配置文件。我已经下载了生产推送 SSL 证书并将其安装在我的钥匙串访问中,将其及其私钥导出,将它们转换为 pem 并将它们合并到一个唯一的 pem 文件中,我将其上传到我的服务器,其中包含发送的 php 脚本通知。 我已将我的 php 脚本中的服务器更改为生产服务器(ssl://gateway.push.apple.com:2195)。 脚本似乎仍然发送通知并且没有触发任何错误。
我错过了什么?
这是我的 php 脚本:
<?PHP
/* Here there's Code to retrieve device tokens and put it in a variable $deviceToken from my online database and then...*/
$message = "Message to be sent";
$payload = '{
"aps" :
{ "alert" : "'.$message.'",
"badge" : 1,
"sound" : "bingbong.aiff"
}
}';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', 'secret');
// se l'app è già sull'appstore togliere sandbox e lasciare solo gateway.push.apple.com:2195
// invece di gateway.sandbox.push.apple.com:2195
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if(!$fp){
print "Failed to connect $err $errstrn";
return;
} else {
print "Notifications sent! </br>";
}
foreach($devArray as $deviceToken){
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack ("n",strlen($payload)) . $payload;
print "sending message :" . $payload . "n to device:".$deviceToken."</br>";
fwrite($fp, $msg);
}
fclose($fp);
?>
【问题讨论】:
-
您的应用程序是否已使用生产配置进行编译?你没有提到它
-
可能 deviceTokens 不正确。你检查过
print "sending message :" . $payload . "n to device:".$deviceToken."</br>";吗? -
是的,已使用生产配置进行编译,并在应用商店发布。我虽然关于令牌。您引用的行报告行,例如“sending message :{ "aps" : { "alert" : "message", "badge" : 1, "sound" : "bingbong.aiff" } }n to device:c016118d79b914dee92d34b66aa334f4ce2a29ccf77026046638632e61b7538d 和 all好像还可以……
-
设备令牌不是有一些空格吗?我不确定,但我相信发送通知会有所不同。
-
不,我修剪它以避免这种情况
标签: ios objective-c push-notification