zoukankan      html  css  js  c++  java
  • 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 检索更多的信息。

    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:字符串’’ 结尾。 AttributeIDS:查找ID列表

    获取APP属性命令 Example

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

    image

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

    image

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

    • CommandID:必须是1
    • AppIdentifier:字符串 ‘’结尾
    • 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

  • 相关阅读:
    web 移动端 适配
    meta
    meta设置
    时间
    CentOS下配置nginx conf/koi-win为同一文件的各类错误
    CentOS7 配置LAMP
    centos 进度条卡死
    LeetCode02:两数相加
    LeetCode01:两数之和
    单链表类,链表逆置
  • 原文地址:https://www.cnblogs.com/sky-heaven/p/5049565.html
Copyright © 2011-2022 走看看