doudui2229
2013-05-21 05:03
浏览 22
已采纳

移动到EC2实例后,APNS推送不工作,而不是“失败”

So, I moved my application to an EC2 instance, and Apple Push Notification Service stopped working. I'm using the same certificate, same script, same everything.

  • I've opened port 2195 in the security group for the EC2 instance.
  • from the EC2 intance, telnet gateway.push.apple.com 2195 works
  • my script receives no errors... everything gets to the end, even fwrite returns true... yet, I receive no push.

Things to note.

  • My EC2 instance is accessed via https where my old server was http, but since the script would be running locally, and has nothing to do with Apache, I don't see why this should matter. But, perhaps it does, so I'm letting you know :D

My script:

$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$ssl = 'ssl://' . $apnsHost . ':' . $apnsPort;
$apns = stream_socket_client($ssl, $error, $errorString, 30, STREAM_CLIENT_CONNECT, $streamContext);
if($apns == false){
    echo "Error: $errorString";
    return false;
}
$payload['aps'] = array('alert' => $message, 'badge'=>$badge, 'sound' => 'default');
$payload = json_encode($payload);

$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $device_id)) . chr(0) . chr(strlen($payload)) . $payload;
if(fwrite($apns, $apnsMessage)){
    return true;
}
return false;

I've checked all of my variables, they are set.

Any help would be greatly appreciated. This is driving me bonkers :P

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题