蘋果通知推送服務(wù)(APNS)一些關(guān)鍵特性摘要
來(lái)源:易賢網(wǎng) 閱讀:1192 次 日期:2015-04-21 13:45:47
溫馨提示:易賢網(wǎng)小編為您整理了“蘋果通知推送服務(wù)(APNS)一些關(guān)鍵特性摘要”,方便廣大網(wǎng)友查閱!

前段時(shí)間,仔細(xì)研究了APNS的文檔,把一些關(guān)鍵的地方記錄了下來(lái),弄懂這些對(duì)于理解APNS的規(guī)則,至關(guān)重要。

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.

假如用戶手機(jī)不在線,可能沒有信號(hào)或者關(guān)機(jī)吧,APNs會(huì)存儲(chǔ)轉(zhuǎn)發(fā),等用戶在線時(shí)再發(fā)送

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.

如果用戶不在線,通知會(huì)合并,只會(huì)保留最新的一條。假如你給用戶發(fā)了兩條通知,但用戶反饋說(shuō),只收到了一條,那么很可能是用戶當(dāng)時(shí)不在線,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.

這個(gè)很重要,payload,就是最后生成的那段Json,不得超過256字節(jié)。如果超過了,建議去掉一些不需要的參數(shù),把a(bǔ)lert,就是提示信息的字?jǐn)?shù)減少

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.

發(fā)送成功的木有返回,只有發(fā)送失敗的才會(huì)返回

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,那么這條之后的通知都需要重發(fā)。有很多開源的庫(kù),在發(fā)蘋果通知時(shí)都沒有檢測(cè)error-response,如果你不小心用了,那么用戶很可能反饋“怎么沒有通知啊”

8.The notification identifier in the error response indicates the last notification that was successfully sent(實(shí)際情況不是,實(shí)際上返回的是出錯(cuò)的那條通知的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.

這是對(duì)上一條的補(bǔ)充,如果出錯(cuò)了,需要關(guān)閉當(dāng)前的連接,并且重新連接再發(fā)。error-response中返回的通知ID,可以幫助我們找出哪條出錯(cuò)了,這樣就能知道哪些需要重發(fā)了

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會(huì)返回那些已經(jīng)卸載的設(shè)備的token--device_token。存儲(chǔ)這些token,下次就不用再給他們發(fā)了,可以節(jié)省點(diǎn)資源。需要注意的是:feedback的接口讀取一次,APNS就會(huì)清空它的列表,下次再讀取時(shí),返回的就是這兩次讀取之間這段時(shí)間新產(chǎn)生的device_token。

只有把這些搞清楚,才方便我們理解蘋果推送的規(guī)則,知道自己推送上的一些不足之處。搞懂這些規(guī)則后,我自己封裝了個(gè)Java的類庫(kù),已經(jīng)開源并放到Github上了,下一篇文章奉上詳情。

更多信息請(qǐng)查看IT技術(shù)專欄

更多信息請(qǐng)查看技術(shù)文章
易賢網(wǎng)手機(jī)網(wǎng)站地址:蘋果通知推送服務(wù)(APNS)一些關(guān)鍵特性摘要
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)