douyuan1049 2013-11-09 05:16
浏览 9
已采纳

生产模式下的推送通知未到来但在开发中它即将到来

My PNS is working good in development mode. I have done this using raywendelich blog. same way i have created certificates in production mode and run same script from server but not receiving any notification.

Which additional step needed when we are testing in production mode from our server.Its very urgent need. plase help what to do for production mode.

our PHP code

<?php

// Put your device token here (without spaces):
$deviceToken = 'd5d89cab86e6f1a3cfa66dd853f3f4d7dd932c4a6da793cb9c86d31e9cfcb31f';

// Put your private key's passphrase here:
$passphrase = '*******';

// Put your alert message here:
$message = '****';

 $ctx = stream_context_create();
 stream_context_set_option($ctx, 'ssl', 'local_cert', 'ckm.pem');
 stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

 // Open a connection to the APNS server
 $fp = stream_socket_client(
'ssl://gateway.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

 if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);

echo 'Connected to APNS' . PHP_EOL;

// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);

  // Encode the payload as JSON
 $payload = json_encode($body);

 // Build the binary notification
 $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload))   . $payload;

 // Send it to the server
 $result = fwrite($fp, $msg, strlen($msg));

 if (!$result)
echo 'Message not delivered' . PHP_EOL;
 else
echo 'Message successfully delivered' . PHP_EOL;

  // Close the connection to the server
  fclose($fp);
  • 写回答

1条回答 默认 最新

  • dongxiongshi9952 2013-11-10 08:33
    关注

    You need to create the production APNS certificate (very similar to the way you created the developer certificate) and use that to connect to Apple instead. The development and production pushtokens are different so in order to get your production push token, you'll have to build an AdHoc version of your app. When you install the ad-hoc version on your device, it should ask you if you want to recieve push tokens. Accept and your code should send your production push token to your server (I'm assuming you save all pushtokens on a server somewhere). This is the token you need to use to test your production push code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度