前段时间,仔细研究了APNS的文档,把一些关键的地方记录了下来,弄懂这些对于理解APNS的规则,至关重要。
1. If APNs attempts to deliver a notification but the device is offline, the notification is stored for a limited period of time, and delivered to the device when it becomes available.
假如用户手机不在线,可能没有信号或者关机吧,APNs会存储转发,等用户在线时再发送
2.Only one recent notification for a particular application is stored. If multiple notifications are sent while the device is offline, each new notification causes the prior notification to be discarded. This behavior of keeping only the newest notification is referred to as coalescing notifications.
如果用户不在线,通知会合并,只会保留最新的一条。假如你给用户发了两条通知,但用户反馈说,只收到了一条,那么很可能是用户当时不在线,APNs的合并策略生效,只保留了最近一条
3.If the device remains offline for a long time, any notifications that were being stored for it are discarded
4.The maximum size allowed for a notification payload is 256 bytes; Apple Push Notification Service refuses any notification that exceeds this limit.
这个很重要,payload,就是最后生成的那段Json,不得超过256字节。如果超过了,建议去掉一些不需要的参数,把alert,就是提示信息的字数减少
5.don’t repeatedly open and close connections. APNs treats rapid connection and disconnection as a denial-of-service attack.
6.If you send a notification that is accepted by APNs, nothing is returned.
发送成功的木有返回,只有发送失败的才会返回
7.If you send a notification that is malformed or otherwise unintelligible, APNs returns an error-response packet and closes the connection. Any notifications that you sent after the malformed notification using the same connection are discarded, and must be resent.
这条非常重要,如果有error-response,那么这条之后的通知都需要重发。有很多开源的库,在发苹果通知时都没有检测error-response,如果你不小心用了,那么用户很可能反馈“怎么没有通知啊”
8.The notification identifier in the error response indicates the last notification that was successfully sent(实际情况不是,实际上返回的是出错的那条通知的ID). Any notifications you sent after it have been discarded and must be resent.When you receive this status code, stop using this connection and open a new connection.
这是对上一条的补充,如果出错了,需要关闭当前的连接,并且重新连接再发。error-response中返回的通知ID,可以帮助我们找出哪条出错了,这样就能知道哪些需要重发了
9.When a push notification cannot be delivered because the intended app does not exist on the device, the feedback service adds that device’s token to its list.
APNS的feedback service会返回那些已经卸载的设备的token--device_token。存储这些token,下次就不用再给他们发了,可以节省点资源。需要注意的是:feedback的接口读取一次,APNS就会清空它的列表,下次再读取时,返回的就是这两次读取之间这段时间新产生的device_token。
只有把这些搞清楚,才方便我们理解苹果推送的规则,知道自己推送上的一些不足之处。搞懂这些规则后,我自己封装了个Java的类库,已经开源并放到Github上了,下一篇文章奉上详情。
相关推荐
苹果推送服务APNS通过C#实现的后台,服务器端源码。应用于IOS提供的移动端推送服务。便于开发者与用户端即时沟通讯息
苹果推送通知服务(APNs)编程
Java APNS推送消息 HTTP/2协议, 基于JDK 11及以上
iOS苹果推送apns测试工具
苹果推送项目源码,运行即用 语言:JAVA,开发IDE:eclipse 数据库:MYSQL 运行即用,附带API调用文档 超级硬通货,想不使用第三方苹果消息推送的千万不要错过
APNS(英文全称:Apple Push Notification Service),中文翻译为:苹果推送通知服务,该技术由苹果公司提供的APNS服务,下面是一个比较完善的苹果推送通知服务的php服务器端公共类.
java实现苹果推送 里面有两个方法实现推送
自己用java实现苹果的apns推送,调用压缩包的text文件里面的方法即可
用https实现iphone消息推送,短连接形式 有问题,请留言
详细的介绍了关于iOS本地推送的原理,以及苹果服务器和客户端交互的机制.
苹果APNS推送,C#实现通过APNS向客户手机推送消息,Apple Push Notification Service
苹果最新技术apns推送!!C#代码!和数据库 VS2008+sql2008
APNS(Apple Push Notification Service)苹果推送通知服务。该技术由苹果公司提供的APNS服务。工作原理:首先,APNS会对用户进行物理连接认证,和设备令牌认证(简言之就是苹果的服务器检查设备里的证书已确定其为...
libcapn, 用于与Apple推送通知服务( APNs ) 交互的简单C 库 libcapn libcapn是一个与苹果推送通知服务的C 库,使用简单直观的API 。 通过该库,你可以轻松地向iOS和 OS X (> = 10.8 ) 设备发送推送通知。版本 2.0与 ...
iphone 推送通知 服务器端java 实现 iphone 推送通知 APNS 包含所需jar包和实现代码
里总结了一份Python搭建苹果推送通知推送服务的相关模块使用指南,包括PyAPNs、基于twisted框架的pyapns以及apns-client三个模块的介绍,需要的朋友可以参考下
利用socket 推送消息到 苹果的服务器。APNS 协议。支持失败重新发送。批量发送等。
主要介绍了C#推送信息到APNs的方法,涉及C#推送通知到苹果APNs的实现技巧,具有一定参考借鉴价值,需要的朋友可以参考下
用于在iOS上实现APNS推送通知并在Android上实现Firebase的插件。 为什么制作此插件? 当前,唯一可用的推送通知插件是firebase_messaging 。 这意味着,即使在iOS上,您也需要设置Firebase并与Google通信以发送推...