简体   繁体   English

iOS无法接收推送通知

[英]iOS Not Receiving Push Notifications

I'm currently in development mode and have created all certificates for development, an app id and a certificate for the APNS. 我目前处于开发模式,并且已创建了所有开发证书,应用程序ID和APNS证书。 ALl have been downloaded and installed on the keychain and the .p12 has been installed in the Server. 已下载AL1并将其安装在钥匙串上,而.p12已安装在服务器中。

All of the devices on the provisioning profile have the app installed and none are receiving the notification. 供应配置文件上的所有设备均已安装该应用程序,并且均未收到该通知。

All ports are open and it has been also tested with a simple php app and it works, but not from the server. 所有端口都是开放的,并且已经通过简单的php应用程序进行了测试,并且可以运行,但不能从服务器运行。

What is missing? 什么东西少了?

It's a bit vague to say that it's working with 'a simple php app'. 说它与“一个简单的PHP应用程序”一起工作有点含糊。 With some more information on the difference between the flow of events on the server and the 'php app', we could probably draw some more reasonable conclusions. 通过更多有关服务器上的事件流与“ php应用程序”之间的区别的信息,我们可能可以得出一些更合理的结论。

Apart from that, if you haven't already, check out this great tutorial by Ali Hafizji from raywenderlich (two parts). 除此之外,如果你还没有,看看这个由阿里Hafizji从raywenderlich伟大的教程(两个部分)。 It has a detailed explanation of pretty much everything you need, I have used it myself a couple of times(looks like it has been updated since then though). 它详细说明了您需要的所有内容,我自己使用了几次(不过从那时起好像已经更新了)。 You say you are installing the .p12 on the server, while I'm pretty sure he's converting it to a .pem-file along with the private key. 您说您正在服务器上安装.p12,而我很确定他会将其与私钥一起转换为.pem文件。

Also make sure the server is using the correct tokens, as your device's token is different in development from what it is in distribution. 还要确保服务器使用正确的令牌,因为您的设备令牌在开发中与在发行中有所不同。

You should also put some health-checks server-side (in the .php or whatever you are using to establish the connection to gateway.push.apple.com ) to make sure your server is actually sending anything. 您还应该在服务器端进行一些运行状况检查(在.php或用于建立与gateway.push.apple.com的连接的任何gateway.push.apple.com ),以确保服务器确实发送了任何内容。 IE if you're using mysql to get access to your tokens, put down a if(!$connection){die(mysql_error());} or something. IE,如果您正在使用mysql来访问令牌,请放置if(!$connection){die(mysql_error());}或其他内容。 This should also be done when establishing the connection to Apple. 建立与Apple的连接时也应该这样做。 With php and stream_socket_client, you could put something like this: 使用php和stream_socket_client,您可以输入如下内容:

$fp = stream_socket_client(
    'ssl://gateway.push.apple.com:2195', $err,
    $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);//$ctx=Stream context

if (!$fp)
    exit("Failed to connect: $err $errstr" . PHP_EOL);

And the actual pushing of the notification, or at least the php-way I've been using, fwrite() returns a boolean for wether it was successful or not, so you can do $result = fwrite($fp, $msg, strlen($msg)); 实际推送通知,或者至少是我一直在使用的php方式, fwrite()返回一个布尔值(无论是否成功),因此您可以执行$result = fwrite($fp, $msg, strlen($msg)); , and $result will be 0 if it fails. ,如果失败, $result将为0。

Also make sure you're connected to the system you intend to use(sandbox or not). 还要确保您已连接到要使用的系统(是否使用沙盒)。 I might be way off here, but I think I once tried to send notifications to my device with production-profile when connecting to Apple's Sandbox-system, and didn't receive anything. 我可能离这里很远,但是我想我曾经尝试在连接到Apple的Sandbox系统时使用生产配置文件将通知发送到我的设备,但是什么也没收到。 You said your certificates were 'development', double-check that everything else is too. 您说您的证书是“开发中的”,请仔细检查其他所有内容。

Then again, I'm having this .php-code on my server, and I'm not completely sure what you meant by 'simple php-app works, but server doesn't'. 再说一遍,我的服务器上有这个.php代码,但我不太确定“简单的php-app可以工作,但服务器不起作用”是什么意思。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM