生产模式下的推送通知不会到来但在开发中它会到来 [英] Push notification in Production mode is not coming But in development it is coming

查看:22
本文介绍了生产模式下的推送通知不会到来但在开发中它会到来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 PNS 在开发模式下运行良好.我已经使用 raywendelich 博客完成了这项工作.我以同样的方式在生产模式下创建证书并从服务器运行相同的脚本但没有收到任何通知.

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.

我们的PHP代码

<?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);

推荐答案

您需要创建生产 APNS 证书(与您创建开发者证书的方式非常相似)并使用它来连接到 Apple.开发和生产推送令牌不同,因此为了获得生产推送令牌,您必须构建应用程序的 AdHoc 版本.当您在设备上安装临时版本时,它应该询问您是否要接收推送令牌.接受并且您的代码应该将您的生产推送令牌发送到您的服务器(我假设您将所有推送令牌保存在某个服务器上).这是您需要用来测试生产推送代码的令牌.

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.

这篇关于生产模式下的推送通知不会到来但在开发中它会到来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆