Php ios推送通知未显示在应用程序中

Php ios推送通知未显示在应用程序中,php,ios,iphone,json,Php,Ios,Iphone,Json,我正在尝试在iOS7应用程序中设置推送通知,但遇到问题 基本上,在创建证书和配置文件的过程中,推送从未出现。目前,我只为开发而建,并将在准备提交时获得发行版。但在开发设置中,一切似乎都是正确的。我制作了一个PHP文件来创建字典格式的消息,我相信这方面的一切都是正确的。passthru代码添加正确,并且我正确连接到APNS服务器(开发端),我可以告诉您这一点,因为当我使我的pass代码不正确时,它会失败 通过阅读与PUSH相关的iOS开发文档,我在手机上添加了一个persistantConnect

我正在尝试在iOS7应用程序中设置推送通知,但遇到问题

基本上,在创建证书和配置文件的过程中,推送从未出现。目前,我只为开发而建,并将在准备提交时获得发行版。但在开发设置中,一切似乎都是正确的。我制作了一个PHP文件来创建字典格式的消息,我相信这方面的一切都是正确的。passthru代码添加正确,并且我正确连接到APNS服务器(开发端),我可以告诉您这一点,因为当我使我的pass代码不正确时,它会失败

通过阅读与PUSH相关的iOS开发文档,我在手机上添加了一个persistantConnection配置文件,并查看了详细的日志文件,根据这些数据,它也应该可以正常工作

我对阅读这些数据并不完全熟悉,但我被告知要寻找的好东西在那里,而坏东西不在那里

我将从设备中附加我的PHP脚本和日志

session_start();
if($_POST['message']){

$deviceToken = array();



$deviceToken[0]="xxxx3ee0 3xxxx973 6bxxxxea 2843xxxx dx5xbx1x x4x8x0xe 7xx65xx9 x61xx01x";


$payload ='{
                "aps" :

                    {   "alert" : "'.$_POST['message'].'"
                        , "badge" : 1
                        , "sound" : "bingbong.aiff"
                    }
            }';




/*
$payload = '
{
    "aps": {
        "alert": "alert",
        "sound": "default"
    },
    "message": "'.$_POST['message'].'",
    "id": 1234
}
';

*/
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'ck.pem';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
stream_context_set_option($streamContext, 'ssl', 'passphrase', "xoxoxoxo");

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);

if(!$apns) {
    print"Stream failed to create ". $error. " ".$errorString;
    return;
} else {
    print"Message Sent";
}

foreach($deviceToken as $key=>$value){



    $apnsMessage = chr(0) . pack("n",32) . pack('H*',str_replace(' ', '', $value)) . pack ("n", strlen($payload)) . $payload;
   // $apnsMessage = chr(0) . chr(0) . chr(32) . @pack('H*', str_replace(' ', '', $value)) . chr(0) . chr(strlen($payload)) . $payload;
    fwrite($apns, $apnsMessage);
    print "<BR>Message Delivered - ". $payload;
}
fclose($apns);
}
?>
<form action="blanket.php" method="post">
<input type="text" placeholder="message" name="message">
<input type="submit" value="submit">
</form>
PHP脚本
session_start();
if($_POST['message']){

$deviceToken = array();



$deviceToken[0]="xxxx3ee0 3xxxx973 6bxxxxea 2843xxxx dx5xbx1x x4x8x0xe 7xx65xx9 x61xx01x";


$payload ='{
                "aps" :

                    {   "alert" : "'.$_POST['message'].'"
                        , "badge" : 1
                        , "sound" : "bingbong.aiff"
                    }
            }';




/*
$payload = '
{
    "aps": {
        "alert": "alert",
        "sound": "default"
    },
    "message": "'.$_POST['message'].'",
    "id": 1234
}
';

*/
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'ck.pem';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
stream_context_set_option($streamContext, 'ssl', 'passphrase', "xoxoxoxo");

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);

if(!$apns) {
    print"Stream failed to create ". $error. " ".$errorString;
    return;
} else {
    print"Message Sent";
}

foreach($deviceToken as $key=>$value){



    $apnsMessage = chr(0) . pack("n",32) . pack('H*',str_replace(' ', '', $value)) . pack ("n", strlen($payload)) . $payload;
   // $apnsMessage = chr(0) . chr(0) . chr(32) . @pack('H*', str_replace(' ', '', $value)) . chr(0) . chr(strlen($payload)) . $payload;
    fwrite($apns, $apnsMessage);
    print "<BR>Message Delivered - ". $payload;
}
fclose($apns);
}
?>
<form action="blanket.php" method="post">
<input type="text" placeholder="message" name="message">
<input type="submit" value="submit">
</form>
session_start();
如果($_POST['message'])){
$deviceToken=array();
$deviceToken[0]=“xxxx3ee0 3xxx973 6xxxxea 2843xxxx dx5xbx1x x4x8x0xe 7xx65xx9 x61xx01x”;
$1{
“aps”:
{“警报”:“'.$\u POST['message']”
“徽章”:1
,“声音”:“bingbong.aiff”
}
}';
/*
$1
{
“aps”:{
“警报”:“警报”,
“声音”:“默认值”
},
“消息”:“'.$\u POST['message']”,
“id”:1234
}
';
*/
$apnsHost='gateway.sandbox.push.apple.com';
$apnsPort=2195;
$apnsCert='ck.pem';
$streamContext=stream_context_create();
stream_context_set_选项($streamContext,'ssl','local_cert',$apnsCert);
stream_context_set_选项($streamContext,'ssl','passphrase','xoxo');
$apns=stream_socket_client('ssl://'.$apnsHost'.:'.$apnsPort,$error,$errorString,2,stream_client_CONNECT,$streamContext);
如果(!$apns){
打印“流未能创建“..$error.”“..$errorString;
返回;
}否则{
打印“已发送消息”;
}
foreach($deviceToken为$key=>$value){
$apnsMessage=chr(0).pack(“n”,32).pack('H*',str_replace('',$value)).pack(“n”,strlen($payload))。$payload;
//$apnsMessage=chr(0).chr(0).chr(32)。@pack('H*',str_replace('',$value)).chr(0).chr(strlen($payload))。$payload;
fwrite($apns,$apnsMessage);
打印“
消息传递-”$payload; } fclose($apns); } ?>
据医生说这就是我要找的

我看到:

查找来自apsd进程的消息。理想情况下,您将看到连接到courier x-courier.sandbox.push.apple.com的站点,其中x是一个小整数。表示设备已成功建立与推送服务的持久连接

我看不出这一点:

另一方面,您可能会看到在连接失败时断开连接。这意味着永久连接失败。在这种情况下,我们的目标是找出导致连接失败的网络状况。检查端口5223上是否没有防火墙阻止TCP通信

我看不出这一点:

消息连接集忽略主题意味着用户选择关闭消息中列出的应用的通知。随后将发送启用哈希的筛选消息,这是iOS实际向APN发送启用和忽略主题的地方

我看不出这一点:

无法解析JSON消息负载的消息表示通知负载中的JSON字典不是有效的JSON格式

糟糕的是,我也看不到这一点:

已启用主题的消息Received message表示设备已收到推送服务的通知

此条件的日志搜索数据“已连接到Courier” 显示良好信息

2014-03-14 14:56:54 -0700 apsd[83]: <APSCourier: 0x16e49ff0> attempting to _connectStream. currently onInterface WWAN consecutiveFailures 0 preference NonCellular shouldUseDualChannel YES. Connected on 1 interfaces.
2014-03-14 14:56:54 -0700 apsd[83]: <APSCourier: 0x16d78f70> attempting to _connectStream. currently onInterface WWAN consecutiveFailures 0 preference NonCellular shouldUseDualChannel YES. Connected on 1 interfaces.
2014-03-14 14:56:54 -0700 apsd[83]: <APSCourier: 0x16d78f70>: Connected to courier 2-courier.sandbox.push.apple.com (17.149.34.142) connection: <APSCourierConnection: 0x16d79810> onInterface: NonCellular
2014-03-14 14:56:54 -0700 apsd[83]: <APSCourier: 0x16e49ff0>: Connected to courier 30-courier.push.apple.com (17.149.36.134) connection: <APSCourierConnection: 0x16d4a380> onInterface: NonCellular
2014-03-14 14:56:55 -0700 apsd[83]: <APSCourier: 0x16d78f70>: Calling into AWD for PushConnectionConnected
2014-03-14 14:56:55 -0700 apsd[83]: <APSCourier: 0x16e49ff0>: Calling into AWD for PushConnectionConnected
2014-03-14 14:57:52 -0700 apsd[83]: <APSCourier: 0x16d78f70> - systemDidLock and we're connected via noncellular, sending inactive ping to the server
2014-03-14 14:57:52 -0700 apsd[83]: <APSCourier: 0x16e49ff0> - systemDidLock and we're connected via noncellular, sending inactive ping to the server
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourierConnection: 0x16d4a380> WWAN is connected; to be consistent, closing the non-cellular connection
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16e49ff0> courierConnection <APSCourierConnection: 0x16d4a380> asked us to disconnect stream on interface NonCellular. Connected on 2 interfaces.
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16e49ff0>: Calling into AWD for ConnectionDisconnected
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16e49ff0> courierConnection <APSCourierConnection: 0x16d4a380> asked us to disconnect stream on interface NonCellular. Connected on 1 interfaces.
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16e49ff0>: Calling into AWD for ConnectionDisconnected
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16e49ff0> attempting to _connectStream. currently onInterface WWAN consecutiveFailures 0 preference None shouldUseDualChannel NO. Connected on 1 interfaces.
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16e49ff0> _connectStream - caller is ensuring that we are connected. We are so there's nothing to do here. - Connected on 1 interfaces.
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourierConnection: 0x16d79810> WWAN is connected; to be consistent, closing the non-cellular connection
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16d78f70> courierConnection <APSCourierConnection: 0x16d79810> asked us to disconnect stream on interface NonCellular. Connected on 2 interfaces.
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16d78f70>: Calling into AWD for ConnectionDisconnected
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16d78f70> courierConnection <APSCourierConnection: 0x16d79810> asked us to disconnect stream on interface NonCellular. Connected on 1 interfaces.
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16d78f70>: Calling into AWD for ConnectionDisconnected
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16d78f70> attempting to _connectStream. currently onInterface WWAN consecutiveFailures 0 preference None shouldUseDualChannel NO. Connected on 1 interfaces.
2014-03-14 14:57:57 -0700 apsd[83]: <APSCourier: 0x16d78f70> _connectStream - caller is ensuring that we are connected. We are so there's nothing to do here. - Connected on 1 interfaces.
2014-03-1414:56:54-0700APSD[83]:试图连接流。当前onInterface WWAN连续故障0首选项非蜂窝应使用双通道是。在1个接口上连接。
2014-03-14 14:56:54-0700APSD[83]:试图连接流。当前onInterface WWAN连续故障0首选项非蜂窝应使用双通道是。在1个接口上连接。
2014-03-14 14:56:54-0700 apsd[83]:连接到courier 2-courier.sandbox.push.apple.com(17.149.34.142)连接:onInterface:非手机
2014-03-14 14:56:54-0700 apsd[83]::连接到courier 30-courier.push.apple.com(17.149.36.134)连接:onInterface:非手机
2014-03-14 14:56:55-0700 apsd[83]::呼叫AWD以连接推送连接
2014-03-14 14:56:55-0700 apsd[83]::呼叫AWD以连接推送连接
2014-03-14 14:57:52-0700 apsd[83]:-systemDidLock,我们通过非蜂窝连接,向服务器发送非活动ping
2014-03-14 14:57:52-0700 apsd[83]:-systemDidLock,我们通过非蜂窝连接,向服务器发送非活动ping
2014-03-14 14:57:57-0700APSD[83]:WWAN已连接;要保持一致,请关闭非蜂窝连接
2014-03-14 14:57:57-0700 apsd[83]:courierConnection要求我们断开非蜂窝接口上的流。在2个接口上连接。
2014-03-14 14:57:57-0700 apsd[83]:呼叫AWD进行连接断开
2014-03-14 14:57:57-0700 apsd[83]:courierConnection要求我们断开非蜂窝接口上的流。在1个接口上连接。
2014-03-14 14:57:57-0700 apsd[83]:呼叫AWD进行连接断开
2014-03-14 14:57:57-0700APSD[83]:试图连接流。当前onInterface WWAN连续故障0首选项无应使用1接口上连接的双通道号。
2014-03-14 14:57:57-0700 apsd[83]:_connectStream-呼叫方正在确保我们已连接。我们