APNS:多次发送相同的通知
我有一个可以发送推送通知的应用程序。当用户在应用程序中保存某些内容时,保存时间会放入我服务器上的 mysql 数据库中的表“active_users”中。我的服务器运行一个脚本来查看时间是否已用完,如果已用完,它会向设备发送通知。
奇怪的是,在系统的第一次测试期间,推送通知到达了我的手机,一切都很顺利。我做了一些更改并再次尝试,但现在似乎什么也没有发生。
这里真正奇怪的是,我有一个push_queue(数据库中的一个表),当需要推送消息(令牌和有效负载)时,会将它们放入其中。当我运行测试时,消息被添加到 push_queue 中,并且在我的日志文件中,所有内容都会被记录,就好像一切正常一样。
我现在的问题是:每个设备令牌只能发送一个推送通知吗?这是我能想到的唯一解决方案。
这是我的日志文件中的粘贴: http://pastebin.com/whkpV3F6 如您所见,两条消息中使用的设备令牌相同。
提前致谢。
I have an app to which I can send push notifications. When a user saves something in the app, the time of saving is put in a mysql-database on my server in the table "active_users". My server runs a script to see if the time has ran out and if it has, it sends a notification to the device.
See the strange thing here is that during the very first test of the system, the push notification reached my phone and everything went well. I did some changes and tried again, but now nothing seems to happen.
What is really strange here is that I have a push_queue (a table in my DB) in which messages to push (token and payload) are put when it is time for them to be pushed. When I run my test, the message is added to the push_queue and in my log-file everything is logged as if it went fine.
My question is now: Can I only send one push notification per device token? This is kinda the only solution I can come up with.
This is a paste from my log-file: http://pastebin.com/whkpV3F6
As you can see, it is the same device token used in both message.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该令牌应该适用于您想要推送到设备的任意数量的消息,除非应用程序已从设备中删除或应用程序已从 Apple 服务器收到新令牌。
如果应用程序被删除,设备幕后的 Apple 会收到通知,并且令牌将失效。您必须“偶尔”向 Apple 询问此反馈,告诉您不应再向哪些令牌发送消息。您必须轮询反馈服务,否则 Apple 将使您发送推送通知的能力失效。
您的应用程序需要在每次启动时向 Apple 请求推送通知服务。您每次取回的令牌可能永远不会改变,但也有可能。然后,您需要确保您的服务器具有正确的令牌。
话虽如此,在这种情况下,您的令牌不太可能发生变化,因为您只是在测试。
更有可能的是,消息只是没有传递……我不相信推送通知一定会传递,就像短信的可靠性一样。我也不认为苹果会阻止你多次发送同一条消息,但我的看法可能是错的;如果快速连续发送重复消息,也许在这方面存在一些限制。不确定那个。
The token should be good for any number of messages you want to push to the device, unless the app has been deleted from the device or the app has received a new token from Apple's servers.
If the app is deleted, behind the scenes on the device Apple is notified and the token becomes invalidated. You must poll Apple "occasionally" for this feedback, telling you which tokens you should no longer send messages to. You MUST poll the feedback service, or Apple will invalidate your ability to send push notifications.
You app needs to request push notification services from Apple on each launch. The token you get back each time may likely never change, but it could. You then need to make sure your server has the correct token.
That all being said, it is unlikely that in your token changed, in this case, since you're just testing.
What is more likely, perhaps, is that the message was just not delivered... I don't believe push notifications are guaranteed to be delivered, much like SMS reliability. I do not think that Apple prevents you from sending the same message more than once, either, but I could be wrong about that; perhaps there is some limiter in that regard if duplicate messages are sent in rapid succession. Not sure about that one.
我自己设法找到了解决方案。这是我的情况和解决方案:
我从 Synology Diskstation (DS211+) 运行我的网络服务器。为了能够通过 PHP 运行打开 SSL 连接,必须启用 openssl。请执行以下操作以在 Synology Diskstation 上启用 PHP:
1) 在 Mac 上打开终端
2) 创建 SSH 连接并以 root 身份连接(使用您的“admin”密码)
3)cd /usr/syno/etc.defaults/
4) vi php.ini
现在使用 /string: /openssl.dll 在 vi 中搜索字符串
该行以分号 (;) 开头,表示它已被注释掉。取消注释“extension=php_openssl.dll”行。
现在使用以下命令重新启动 apache 服务器:
/usr/syno/etc.defaults/rc.d/S97apache-user.sh restart
现在应该可以正常工作了。
I managed to find the solution myself. This is my situation and solution:
I run my webserver from a Synology Diskstation (DS211+). To be able to run open an SSL-connection via PHP, openssl must be enabled. Do the following to enable PHP on you Synology Diskstation:
1) Open the terminal on your mac)
2) Create an SSH-connection and connect as root (user your "admin"-password)
3) cd /usr/syno/etc.defaults/
4) vi php.ini
Now search for a string in vi using /string: /openssl.dll
This line starts with a semicolon (;) which means that it is commented out. Uncomment the line "extension=php_openssl.dll".
Now restart the apache server using the following command:
/usr/syno/etc.defaults/rc.d/S97apache-user.sh restart
It should now work perfectly.