[英]Push notifications work for development, not production
I have been trying for the past how long to figure out how to go from the sandbox APNS to production APNS. 过去,我一直在尝试找出从沙盒APNS转到生产APNS的时间。 Below is the PHP code used to send notifications to my app.
以下是用于向我的应用发送通知的PHP代码。
$passphrase = 'SomethingStrong';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $_SERVER['DOCUMENT_ROOT'] . '/ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
{
//return json_encode(array('response' => 'connection_fail'));
}
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
return json_encode(array('response' => 'unsuccessful'));
else
return json_encode(array('response' => 'successful'));
fclose($fp);
This whole thing works when I keep the URL ssl://gateway.sandbox.push.apple.com:2195
, but when I when I change it to ssl://gateway.push.apple.com:2195
no notifications come through my app, yet PHP outputs that it was sent successfully. 当我保留URL
ssl://gateway.sandbox.push.apple.com:2195
,整个过程都有效,但是当我将其更改为ssl://gateway.push.apple.com:2195
没有任何通知通过我的应用程序,但是PHP输出它已成功发送。
I'm code-signing with the development certificates. 我正在使用开发证书进行代码签名。
I'm new to notifications and have never used them before, so sorry if I'm doing something really obvious. 我是通知的新手,以前从未使用过它们,所以如果我做的事情很明显,对不起。 Thanks.
谢谢。
You are setting the correct ssl socket ssl://gateway.push.apple.com:2195
for production. 您正在为生产设置正确的ssl套接字
ssl://gateway.push.apple.com:2195
。
Check the certificates or the ck.pem
file you have upload to server should be production. 检查证书或已上传到服务器的
ck.pem
文件应为生产环境。
Also check for the provisioning profile which you select for build should be Distribution profile . 另外,请检查您选择的构建应该是分布曲线的供应配置文件 。
Everything was setup correctly, but I had an issue with my Ad Hoc profile and the way it was code-signing. 一切都设置正确,但是我的临时配置文件及其代码签名方式出现问题。 All is good now!
现在一切都好! Thanks!
谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.