文本档覆盖的内容中除特别描述外,和字节序相关的都是用Little-endian (小端模式)。 文本档覆盖的内容中除特别描述外,和字符串传递相关的都是UTF-8
Note: ANCS 并不保证始终存在,服务开启,关闭机制由iOS系统决定,Device 需要一直检测,查找ANCS是否存在。
ANCS的uart profile UUID : ” 7905F431-B5CE-4E99-A40F-4B1E122D00D0”
uart profile 中包括3个 characteristic
Device端Notification Source 是必须实现的。Centrol Point 和 Data Source 可选。
Notification Source characteristic 包括3个功能
当Device端 subscribes Notification Source characteristic时,GATT Notification 会立刻分发出去。所以,Notification consumer (Device)在subscribe之前就需要做好立马接受和处理消息的状态。
图2-1 Notification Source characteristic 通过GATT Notification 的格式。
表格3-1:CategoryID的描述
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
只是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”
图2-4 获取通知属性命令返回数据格式
CommandID: 0 NotificationUID:通知的唯一标示 AttributeList:具体的属性返回数据列表. 如果返回的属性空,长度是0
如果返回的数据长度大于 GATT MTU,那么数据会被分几段传输。Device 需要对数据拼接。
下图查找 NotificationUID为2的 AppIdentifier、Title、SubTitle、Message Date属性返回数据
该命令通过APPIdentifier查找iOS设备中安装的APP的属性。
图2-5 获取APP属性命令格式
CommandID: 必须设置成1 AppIdentifier:字符串’\0’ 结尾。 AttributeIDS:查找ID列表
查找AppIdentifier 为 “com.apple.mobilemail” 的APP属性
图2-6获取APP属性命令返回数据格式
如果返回的数据长度大于 GATT MTU,那么数据会被分几段传输。Device 需要对数据拼接。
查找AppIdentifier 为 “com.apple.mobilemail” 的APP属性返回数据 汉字 “邮件”
ANCS 的 session 从设备订阅characteristic 开始到取消订阅或是disconnect结束。所有的Identifier 比如 NotificationUID,AppIdentifier 只在当前的session有效。
当session结束后,设备需要删除掉所有的在session中获得的Identifier信息,这些信息会在session建立的时候重新通知设备.
注意:如果产生了上面的错误,都不会再收到任何的GATT 通知。