ios推送通知没有出现在App中

时间:2022-09-10 20:21:11

I am trying to set up push notifications in my iOS7 app and am running into issues.

我试图在iOS7应用中设置推送通知,但遇到了一些问题。

Basically the push never shows up I when through the process of creating the certificates and the provisioning profiles. Currently I only have it built for development and will get the distribution one made up when I am ready to submit it. But in the development setup everything appears to be correct. I made a PHP file to create the message in dictionary format and I believe everything is correct on that side of things. The passthru code is addedd correctly and I connect to the APNS server correctly (the development side) I can tell this because when I make my pass code incorrect it does fail.

基本上,在创建证书和配置文件的过程中,push从来不会出现在I中。目前我只为开发构建了它,当我准备提交它时就会得到一个发行版。但在开发设置中,一切似乎都是正确的。我做了一个PHP文件来创建字典格式的消息,我相信这方面的一切都是正确的。passthru代码是addedd正确的,我正确地连接到APNS服务器(开发端),我可以告诉它,因为当我把我的密码错误的时候,它确实失败了。

From going through the iOS development documents related to PUSH I added a persistantConnection profile onto my phone and view the detailed log files and according to that data it should also be working.

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

I am not totally familiar with reading this data but the good things I was told to look for were there and the bad things were not.

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

I will attach my PHP script and the log from the device

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

PHP script

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>

According to the doc this is what I am looking for

根据医生的说法,这就是我要找的

I see this:

我看到这个:

Look for messages from the apsd process. Ideally you'll see Connected to courier x-courier.sandbox.push.apple.com where x is a small integer. That indicates that the device has successfully established its persistent connection to the push service.

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

I do not see this:

我没有看到这个:

You might on the other hand see Disconnecting in response to connection failure. That means that the persistent connection failed. In that case, the goal is to figure out what's going on with your network that's causing the connection failure. Check that no firewalls are blocking TCP traffic on port 5223.

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

I do not see this:

我没有看到这个:

The message connection set ignored topics means that the user chose to turn off notifications for the apps listed in the message. That will be followed by Sending filter message for enabled hashes which is where iOS actually sends the enabled and ignored topics to APNs.

消息连接设置忽略的主题意味着用户选择关闭消息中列出的应用程序的通知。然后,为启用的散列发送过滤器消息,这是iOS实际将启用和忽略的主题发送到APNs的地方。

I do not see this:

我没有看到这个:

The message Failed to parse JSON message payload indicates that the JSON dictionary in the notification payload is not in valid JSON format.

解析JSON消息有效负载的消息失败表明通知有效负载中的JSON字典不是有效的JSON格式。

The bad part is I also do not see this:

不好的是我也没看到这个:

The message Received message for enabled topic means that the device received a notification from the push service.

为enabled topic接收消息意味着设备收到来自push服务的通知。

DATA FROM LOG search for this criteria "Connected to Courier" showing good info

从日志搜索的数据,这个标准“连接到快递”显示良好的信息

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.

As far as I can tell it should be working but it is not.

就我所知,它应该是有效的,但它不是。

Any ideas?

什么好主意吗?

1 个解决方案

#1


1  

Can you try to remove the white space between the device token so that your device token will look like

您是否可以尝试删除设备令牌之间的空白,使您的设备令牌看起来像这样

$deviceToken[0]="xxxx3ee03xxxx9736bxxxxea2843xxxxdx5xbx1xx4x8x0xe7xx65xx9x61xx01x";

As per my knowedge , device token should not contain any white space & symbols < , >

根据我的知识,设备令牌不应该包含任何空格和符号<,>。

Also check the return code from request & feedback service to give you information about failed push notifications as mentioned here

还可以检查请求和反馈服务的返回代码,以提供有关失败的推送通知的信息

Please let me know if it works

如果可以的话,请告诉我

#1


1  

Can you try to remove the white space between the device token so that your device token will look like

您是否可以尝试删除设备令牌之间的空白,使您的设备令牌看起来像这样

$deviceToken[0]="xxxx3ee03xxxx9736bxxxxea2843xxxxdx5xbx1xx4x8x0xe7xx65xx9x61xx01x";

As per my knowedge , device token should not contain any white space & symbols < , >

根据我的知识,设备令牌不应该包含任何空格和符号<,>。

Also check the return code from request & feedback service to give you information about failed push notifications as mentioned here

还可以检查请求和反馈服务的返回代码,以提供有关失败的推送通知的信息

Please let me know if it works

如果可以的话,请告诉我