本文介绍了Apple 推送通知服务 APNS - 通知未到达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向我的应用添加推送通知.我正在使用临时配置文件.我的 appID 没有通配符.我正在使用以下 php 代码...

I am trying to add push notifications to my app. I have am using an ad hoc profile. My appID does not have a wildcard. I am using the following php code...

$deviceToken="****";masked
$time = time();

 $apnsHost = 'gateway.sandbox.push.apple.com';

$apnsPort = 2195;
$apnsCert = 'apns-dev-maui.pem';

$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
if($apns)
{
echo "Connection Established<br/>";
$payload = array();
$payload['aps'] = array('alert' => 'It works!!', 'badge' => 1, 'sound' => 'default');
$payload = json_encode($payload);
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;

        print "sending message :" . $apnsMessage . "<br/>";
        print "sending payload :" . $payload . "<br/>";
        fwrite($apns, $apnsMessage);

}
else
{
        echo "Connection Failed";
        echo $errorString;
        echo $error;
}
// socket_close($apns);
fclose($apns);

不会产生连接错误.反馈渠道似乎没有任何消息.


No connection errors are generated. Nothing seems to be coming from the feedback channel.

我从管理器控制台和 NSLog 命令获得了 deviceTokens.此应用的通知显示在我的设置菜单中.

I got the deviceTokens from the organizer console and an NSLog command. The notifications for this app are showing up in my settings menu.

我有一个 ATT 3G 和一个用作 iPod 的旧 2G.都不行.

I have an ATT 3G and an old 2G that I use as an iPod. Neither work.

没有错误可看,我没有想法.任何人有任何见解?

With no errors to look at, I am out of ideas. Anyone have any insight?

詹妮弗

推荐答案

我终于想通了.我使用的是带有 AdHoc 配置文件的 Sandbox.Ad Hoc 显然被认为是生产而不是开发.我创建了推送生产证书,安装了它,瞧!它有效.

I finally figured it out. I was using Sandbox with an AdHoc provisioning profile. Ad Hoc is apparently considered production instead of development. I created the push production certificate, installed it and voila! It works.

这篇关于Apple 推送通知服务 APNS - 通知未到达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 14:14