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

Posted by studentdeng Mar 22nd, 2014  iOS

Apple Notification Center Service--ANCS【转】的更多相关文章

  1. Apple iOS MDM service 简介

    Apple iOS MDM service 簡介 藉由MDM服務,企業可以用來控管配發給員工的iOS Device.可以採用Apple官方推出的工具,也可以採用第三方開發的服務. MDM server ...

  2. iOS 7 Pushing the Limits Notes - create a layer like notification center's or control center's background

    Problem: How to create a layer that looks like your notification center's or control center's backgr ...

  3. IOS8 通知中心(Notification Center)新特性

     本文转载至 http://blog.csdn.net/jinkaiouyang/article/details/30029441   ios手机apple通知中心notificationCenter ...

  4. ANCS协议翻译

    综述 苹果通知中心(Apple Notification Center Service, ANCS)的目的是提供给蓝牙外设一种简单.方便的获取ios设备通知信息的方式. 依赖 ANCS的使用没有依赖, ...

  5. 苹果ANCS协议学习【转】

    苹果ANCS协议学习 转自:http://www.cnblogs.com/alexcai/p/4321514.html 综述 苹果通知中心(Apple Notification Center Serv ...

  6. 蓝牙接收苹果手机通知 ANCS协议分析

    蓝牙接收苹果手机通知 ANCS协议分析 转载,请注明出处:http://www.cnblogs.com/alexcai/p/4321514.html 综述 现在有许多蓝牙手表.手环都能接收苹果ipho ...

  7. 原创翻译:蓝牙(BLE)for iOS

    About Core Bluetooth 简要:核心蓝牙框架提供了iOS和MAC 应用程序与BLE 设备进行无线通信所需要的类.通过该框架,应用程序可以扫描.发现BLE 外设,如心率.电子温度传感器等 ...

  8. (转)Apple Push Notification Services in iOS 6 Tutorial: Part 2/2

    转自:http://www.raywenderlich.com/32963/apple-push-notification-services-in-ios-6-tutorial-part-2 Upda ...

  9. [Erlang 0106] Erlang实现Apple Push Notifications消息推送

        我们的IOS移动应用要实现消息推送,告诉用户有多少条消息未读,类似下图的效果(笑果),特把APNS和Erlang相关解决方案笔记于此备忘.          上面图片中是Apple Notif ...

随机推荐

  1. nginx配置虚拟路径下载文件(.apk)

    公司将安卓apk文件放到服务器上,实现用户点击链接并下载 nginx version 1.14.1 nginx配置修改 server { listen 80; server_name localhos ...

  2. 九省LNOI2018退役记

    立个flag不会退役. Day 0: 水一发. 大连大学的键盘敲起来就跟敲纸似的. 膜拜要进队的gqh,yxd,sjq. (都进啦2333) (高斯消元,高原反应,分麾下治……) 给我这只弱鸡烧根香. ...

  3. uoj132/BZOJ4200/洛谷P2304 [Noi2015]小园丁与老司机 【dp + 带上下界网络流】

    题目链接 uoj132 题解 真是一道大码题,,,肝了一个上午 老司机的部分是一个\(dp\),观察点是按\(y\)分层的,而且按每层点的上限来看可以使用\(O(nd)\)的\(dp\),其中\(d\ ...

  4. CentOS7单节点部署redis主从复制和sentinel

    准备一台机器,系统版本为CentOS7. 部署redis 1.下载软件包 # wget http://download.redis.io/releases/redis-3.2.8.tar.gz 2.解 ...

  5. java多线程 -- ReadWriteLock 读写锁

    写一条线程,读多条线程能够提升效率. 写写/读写 需要“互斥”;读读 不需要互斥. ReadWriteLock 维护了一对相关的锁,一个用于只读操作,另一个用于写入操作.只要没有 writer,读取锁 ...

  6. 解题:USACO13JAN Island Travels

    题面 好像没啥可说的,就当练码力了...... 先用BFS跑出岛屿,然后跑最短路求岛屿间的距离,最后状压DP得出答案 注意细节,码码码2333 #include<set> #include ...

  7. [SDOI2009] HH去散步 (矩阵乘法)

    link $solution:$ 将边化为点后重新建矩阵,跑$T-1$幂即可(因为跑的是新边). 最后直接找与$x,y$所相连的边即可. #include<iostream> #inclu ...

  8. struts2的MVC模式

    MVC是一种架构型模式,它本身并不引入新的功能,只是用来指导我们改善应用程序的架构,使得应用的模型和视图相分离,从而得到更好的开发和维护效率. 在MVC模式中,应用程序被划分成了模型(Model).视 ...

  9. 题解【bzoj4587 & bzoj4408 [FJOI2016]神秘数】

    Description \(n\) 个数的序列,每次询问一个区间,求最小的一个数使得不能用这个区间中的数之和表示. \(n \leq 10^5, \sum a_i \leq 10^9\) 这两个题一个 ...

  10. python基础之生成器迭代器

    1 生成器: 为什么要有生成器? 就拿列表来说吧,假如我们要创建一个list,这个list要求格式为:[1,4,9,16,25,36……]这么一直持续下去,直到有了一万个元素的时候为止.如果我们要创建 ...