Apple Notification Center Service--ANCS【转】

Apple Notification Center Service

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

MAR 22ND, 2014 | COMMENTSios

名词解释与约定

名词解释

  • 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-8git

Note: ANCS 并不保证始终存在,服务开启,关闭机制由iOS系统决定,Device 须要一直检测,查找ANCS是否存在。github

协议内容

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

uart profile 中包括3个 characteristicapp

  • 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 可选。ide

Notification Source Characteristic

Notification Source characteristic 包括3个功能spa

  • 新的iOS设备通知
  • iOS设备通知修改
  • iOS设备通知删除

当Device端 subscribes Notification Source characteristic时,GATT Notification 会马上分发出去。因此,Notification consumer (Device)在subscribe以前就须要作好立马接受和处理消息的状态。3d

Notification Source response format

图2-1 Notification Source characteristic 经过GATT Notification 的格式。orm

  • EventID:描述iOS设备上面的通知是增长、删除、仍是修改。
  • EventFlags: 标志位,描述iOS设备通知(重要, 静默)
  • CategoryID:iOS设备通知类型
  • CategoryCount:给定类型的通知数量,好比有2个未读email消息通知,这时有一个新的未读消息通知push到iOS设备,这时CategoryCount = 3 NotificationUID:通知的惟一标示,这个字段用于和Control Point characteristic 检索更多的信息。

image

表格3-1:CategoryID的描述

image

Notification Source Response Example

Device 获取的来此Notification Source的数据是“00 01 00 01 43 00 00 00”

image

图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 查找通知的详细内容(通知属性)。

image

图2-3 获取通知属性命令格式 CommandID: 必须设置为0 NotificationUID:通知的惟一标示(Notification Source 得到) AttributeIDS:须要检索信息list

image

图3-5 能够检索的通知属性列表,其中Title, subtitle, Message 须要增长2个bytes的字段表示长度。

获取通知属性命令Example “00 43 00 00 00 00 01 FF FF 05”

image

获取通知属性命令Response消息格式

image

图2-4 获取通知属性命令返回数据格式

CommandID: 0 NotificationUID:通知的惟一标示 AttributeList:具体的属性返回数据列表. 若是返回的属性空,长度是0

若是返回的数据长度大于 GATT MTU,那么数据会被分几段传输。Device 须要对数据拼接。

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

下图查找 NotificationUID为2的 AppIdentifier、Title、SubTitle、Message Date属性返回数据

image

获取APP属性命令

该命令经过APPIdentifier查找iOS设备中安装的APP的属性。

图2-5 获取APP属性命令格式

CommandID: 必须设置成1 AppIdentifier:字符串’\0’ 结尾。 AttributeIDS:查找ID列表

获取APP属性命令 Example

查找AppIdentifier 为 “com.apple.mobilemail” 的APP属性

image

获取APP属性命令Response消息格式

image

图2-6获取APP属性命令返回数据格式

  • CommandID:必须是1
  • AppIdentifier:字符串 ‘\0’结尾
  • AttributeList:具体的属性返回数据列表. 若是返回的属性空,长度是0

若是返回的数据长度大于 GATT MTU,那么数据会被分几段传输。Device 须要对数据拼接。

获取APP属性命令Response消息格式Example

查找AppIdentifier 为 “com.apple.mobilemail” 的APP属性返回数据 汉字 “邮件”

image

sessions会话

ANCS 的 session 从设备订阅characteristic 开始到取消订阅或是disconnect结束。全部的Identifier 好比 NotificationUID,AppIdentifier 只在当前的session有效。

当session结束后,设备须要删除掉全部的在session中得到的Identifier信息,这些信息会在session创建的时候从新通知设备.

错误代码

  • 未知命令:(0xA0)
  • 无效命令:(0xA1)
  • 无效参数(0xA2) : 好比NotificationUID 找不到

注意:若是产生了上面的错误,都不会再收到任何的GATT 通知。

参考内容

Apple Notification Center Service (ANCS) Specification

相关文章
相关标签/搜索