douchang6770 2016-03-03 04:08
浏览 65

推送通知适用于开发,而非生产

I have been trying for the past how long to figure out how to go from the sandbox APNS to production APNS. Below is the PHP code used to send notifications to my app.

$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.

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.

  • 写回答

3条回答 默认 最新

  • douzhi9478 2016-03-03 04:47
    关注

    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

    Push Notification Certificate

    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置