ios推送通知未显示在App中

时间:2014-03-15 00:14:00

标签: php ios iphone json

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

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

从浏览与PUSH相关的iOS开发文档后,我在手机上添加了一个persistantConnection配置文件,并查看详细的日志文件,根据该数据,它也应该正常工作。

我对阅读这些数据并不完全熟悉,但我告诉他要找的好东西都在那里而且坏的东西都没有。

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

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>

根据文件,这是我正在寻找的

我明白这一点:

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

我没有看到这个:

另一方面,您可能会看到断开连接以响应连接失败。这意味着持久连接失败。在这种情况下,目标是弄清楚导致连接失败的网络正在发生什么。检查没有防火墙阻止端口5223上的TCP流量。

我没有看到这个:

忽略主题消息连接集意味着用户选择关闭消息中列出的应用程序的通知。接下来是为已启用的哈希发送过滤器消息,这是iOS实际将启用和忽略的主题发送到APN的位置。

我没有看到这个:

无法解析JSON消息有效内容的消息表明通知有效内容中的JSON字典不是有效的JSON格式。

不好的部分是我也看不到:

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

DATA FROM LOG搜索此条件“已连接至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.

据我所知,它应该有效,但事实并非如此。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您是否可以尝试删除设备令牌之间的空白区域,以便您的设备令牌看起来像

$deviceToken[0]="xxxx3ee03xxxx9736bxxxxea2843xxxxdx5xbx1xx4x8x0xe7xx65xx9x61xx01x";

根据我的知识,设备令牌不应包含任何空格&amp;符号&lt; ,&gt;

同时检查请求中的返回代码&amp;反馈服务,为您提供有关here

提及的失败推送通知的信息

如果有效,请告诉我