简体   繁体   English

推送通知是为了开发而不是生产而工作

[英]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. 谢谢。

There are two things, you need to confirm: 有两件事,您需要确认:

  • You generate your build with distribution provisioning profile 您可以使用分发配置概要文件生成构建
  • You use production pem file for sending PUSH from your PHP server 您使用生产pem文件从PHP服务器发送PUSH

推送通知证书

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM