日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Apple Notification Center Service--ANCS【转】

發布時間:2025/3/17 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Apple Notification Center Service--ANCS【转】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Apple Notification Center Service

轉自:http://studentdeng.github.io/blog/2014/03/22/ancs/

MAR 22ND, 2014?|?COMMENTS

名詞解釋與約定

名詞解釋

  • Apple Notification Center Service 簡稱 ANCS。
  • ANCS 服務(iOS設備,如iPhone,iPad等)的publisher 稱為 Notification Provider。
  • 任意的ANCS服務的client(硬件設備,配件)稱為 Notification Consumer。
  • Generic Attribute Profile簡稱GATT。
  • 在iOS NotificationCenter 顯示的通知稱為 iOS notification。
  • 通過GATT characteristic 發布的通知稱為 GATT notification。
  • iPhone、 iPad等運行iOS系統的設備稱為iOS設備

約定

文本檔覆蓋的內容中除特別描述外,和字節序相關的都是用Little-endian (小端模式)。 文本檔覆蓋的內容中除特別描述外,和字符串傳遞相關的都是UTF-8

Note:?ANCS 并不保證始終存在,服務開啟,關閉機制由iOS系統決定,Device 需要一直檢測,查找ANCS是否存在。

協議內容

ANCS的uart profile UUID : ” 7905F431-B5CE-4E99-A40F-4B1E122D00D0”

uart profile 中包括3個 characteristic

  • Notification Source UUID: “9FBF120D-6301-42D9-8C58-25E699A21DBD” (notifiable)
  • Control Point UUID: “69D1D8F3-45E1-49A8-9821-9BBDFDAAD9D9”(write with response)
  • Data Source UUID:” 22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB “(notifiable)

Device端Notification Source 是必須實現的。Centrol Point 和 Data Source 可選。

Notification Source Characteristic

Notification Source characteristic 包括3個功能

  • 新的iOS設備通知
  • iOS設備通知修改
  • iOS設備通知刪除

當Device端 subscribes Notification Source characteristic時,GATT Notification 會立刻分發出去。所以,Notification consumer (Device)在subscribe之前就需要做好立馬接受和處理消息的狀態。

Notification Source response format

圖2-1 Notification Source characteristic 通過GATT Notification 的格式。

  • EventID:描述iOS設備上面的通知是增加、刪除、還是修改。
  • EventFlags: 標志位,描述iOS設備通知(重要, 靜默)
  • CategoryID:iOS設備通知類型
  • CategoryCount:給定類型的通知數量,比如有2個未讀email消息通知,這時有一個新的未讀消息通知push到iOS設備,這時CategoryCount = 3 NotificationUID:通知的唯一標示,這個字段用于和Control Point characteristic 檢索更多的信息。

表格3-1:CategoryID的描述

Notification Source Response Example

Device 獲取的來此Notification Source的數據是“00 01 00 01 43 00 00 00”

圖2-2一個iOS通知的生命周期。

比如當iOS設備(如iPhone)收到一個iMessage消息,iOS NotificationCenter會產生一個Notification,ANCS會通知device 有一個新的通知。當iOS設備閱讀這個iMessage消息之后,iOS Not ificationCenter 會刪除掉這個通知,ANCS把這個刪除通知push到device

Control Point 和 Data Source Characteristic

只是Notification Source 不能獲得足夠的信息, Control Point 和 Data Source characteristic用來解決這個問題。 Device 向Control Point characteristic 寫一個命令,如果成功,會從DataSource characteristic 獲得response。

獲取通知屬性命令

該命令根據NotificationUID 查找通知的詳細內容(通知屬性)。

圖2-3 獲取通知屬性命令格式 CommandID: 必須設置為0 NotificationUID:通知的唯一標示(Notification Source 獲得) AttributeIDS:需要檢索信息list

圖3-5 可以檢索的通知屬性列表,其中Title, subtitle, Message 需要增加2個bytes的字段表示長度。

獲取通知屬性命令Example “00 43 00 00 00 00 01 FF FF 05”

獲取通知屬性命令Response消息格式

圖2-4 獲取通知屬性命令返回數據格式

CommandID: 0 NotificationUID:通知的唯一標示 AttributeList:具體的屬性返回數據列表. 如果返回的屬性空,長度是0

如果返回的數據長度大于 GATT MTU,那么數據會被分幾段傳輸。Device 需要對數據拼接。

通知屬性命令Response 消息格式Example

下圖查找 NotificationUID為2的 AppIdentifier、Title、SubTitle、Message Date屬性返回數據

獲取APP屬性命令

該命令通過APPIdentifier查找iOS設備中安裝的APP的屬性。

圖2-5 獲取APP屬性命令格式

CommandID: 必須設置成1 AppIdentifier:字符串’\0’ 結尾。 AttributeIDS:查找ID列表

獲取APP屬性命令 Example

查找AppIdentifier 為 “com.apple.mobilemail” 的APP屬性

獲取APP屬性命令Response消息格式

圖2-6獲取APP屬性命令返回數據格式

  • CommandID:必須是1
  • AppIdentifier:字符串 ‘\0’結尾
  • AttributeList:具體的屬性返回數據列表. 如果返回的屬性空,長度是0

如果返回的數據長度大于 GATT MTU,那么數據會被分幾段傳輸。Device 需要對數據拼接。

獲取APP屬性命令Response消息格式Example

查找AppIdentifier 為 “com.apple.mobilemail” 的APP屬性返回數據 漢字 “郵件”

sessions會話

ANCS 的 session 從設備訂閱characteristic 開始到取消訂閱或是disconnect結束。所有的Identifier 比如 NotificationUID,AppIdentifier 只在當前的session有效。

當session結束后,設備需要刪除掉所有的在session中獲得的Identifier信息,這些信息會在session建立的時候重新通知設備.

錯誤代碼

  • 未知命令:(0xA0)
  • 無效命令:(0xA1)
  • 無效參數(0xA2) : 比如NotificationUID 找不到

注意:如果產生了上面的錯誤,都不會再收到任何的GATT 通知。

參考內容

Apple Notification Center Service (ANCS) Specification


本文轉自張昺華-sky博客園博客,原文鏈接:http://www.cnblogs.com/sky-heaven/p/5049565.html,如需轉載請自行聯系原作者

總結

以上是生活随笔為你收集整理的Apple Notification Center Service--ANCS【转】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。