思澈科技软件开发工具包  2.20
ANCS客户端

ANCS 介绍

Apple 通知中心服务(ANCS)是 IOS 设备中的 GATT 服务。 该服务可以通知配件在 IOS 设备中的通知,称为 Nofication Provider(NP)。 本地设备充当附件,称为通知消费者(NC)。

NP有3个特点:

  • 通知来源 NC 启用 CCCD 后,通知源特性将发送带有 categoryID 和计数的通知。
    通知数据格式
    • 事件 ID 通知 NC 是否添加、修改或删除通知。
    • EventFlags 通知通知的特殊性。 NC 可以决定是通知用户还是只是过滤。
    • CategoryID 通知通知的类别,如来电、新闻或消息。
    • CategoryCount 通知通知中心中存在的通知计数。
    • NotificationUID 是用于标识类别的 32 位 ID。
  • 控制点和数据源

    NC 可以向控制点写入命令以与 NP 交互以获取详细信息或执行操作。 有3个命令:

    • 获取通知属性。 此命令允许 NC 从 Notification 检索通知的模式详细信息。
      获取通知属性命令格式
      • CommandID 应设置为 0
      • NotificationUID 来自通知源的通知。
      • AttributeIDs是NC想要获取更多详细信息的通知属性。
        获取通知属性命令的响应格式
      • CommandID、Notification UID、Attribute_ID 都与 get Notification Attributes 命令相同。
      • 属性长度和属性是与属性ID 相关联的长度和数据。 数据包括详细信息。
    • 获取APP属性。 该命令允许 NC 检索已安装 APP 的详细信息。
      获取APP属性命令格式
      • CommandID 应设置为 1
      • APP Identifier 是从通知 APP_ID 属性中获取的字符串 ID。 表示在IOS中注册的APP ID。
      • APP AttributeIDs是NC想要获取更多详细信息的APP属性。
        获取APP属性命令的响应格式
      • CommandID、APP Identifier 与 get APP Attributes 命令相同。
      • 属性长度和属性是与属性ID 相关联的长度和数据。 数据包括详细信息。
    • 执行通知操作。 此命令允许 NC 对特定 IOS 通知执行预定操作。 有两个动作:
      1. 积极行动
      2. 消极行动 IOS 会根据动作执行行为,但UI 行为取决于IOS 和通知。 例如,如果通知是来电,则积极动作可能会接听它,而消极动作可能会拒绝它。 但行为可能会在其他通知中改变。

实施 ANCS NC

Sibles ANCS 提供 API 来搜索 IOS 设备中的 ANCS 并配置通知属性。 用户只需要执行以下操作:

  1. 配置预期的通知和 APP 属性和关联长度。
  2. 收到APP_ID属性信息后,使用相关API获取APP属性。
  3. 使用 perform action API 为指定的 attributeID 执行动作。

有关 ANCS API 的详细信息,请参阅 ANCS .

这是示例代码:

int app_ancs_event_handler(uint16_t event_id, uint8_t *data, uint16_t len, uint32_t context)
{
switch (event_id)
{
// ANCS only allows paired device to access its service.
{
rt_kprintf("encryt ind %d", ind->conn_idx);
// configure attributes and its length.
// enable ANCS
break;
}
{
// Go through all attributes data.
rt_kprintf("received_notify %d, attr_count %d\r\n", notify->evt_id, notify->attr_count);
!(notify->evt_flag & BLE_ANCS_EVENT_FLAG_PRE_EXISTING)) // No need to shown pre-existing notifcations
{
ble_ancs_attr_value_t *value = notify->value;
ble_ancs_dev_app_id_name_t *app_id_name;
uint32_t i;
for (i = 0; i < notify->attr_count; i++)
{
if (value->len == 0)
{
value = (ble_ancs_attr_value_t *)((uint8_t *)value + sizeof(ble_ancs_attr_value_t));
continue;
}
if (value->attr_id == BLE_ANCS_NOTIFICATION_ATTR_ID_TITLE)
{
// Handle title content.
}
else if (value->attr_id == BLE_ANCS_NOTIFICATION_ATTR_ID_APP_ID)
{
// Get APP attribute
ble_ancs_get_app_attr(app_id, value->len + 1);
}
else if (value->attr_id == BLE_ANCS_NOTIFICATION_ATTR_ID_MESSAGE)
{
// Handle message content.
}
value = (ble_ancs_attr_value_t *)((uint8_t *)value + sizeof(ble_ancs_attr_value_t) + value->len);
}
break;
}
break;
}
{
// Handle APP display name
break;
}
default:
break;
}
return 0;
}
// Reigster event to listen ancs events.
BLE_EVENT_REGISTER(app_ancs_event_handler, NULL);
ble_ancs_noti_attr_t::evt_id
uint8_t evt_id
Definition: bf0_ble_ancs.h:257
len
uint16_t len
Definition: bf0_ble_ancs.h:226
ble_ancs_noti_attr_t::attr_count
uint8_t attr_count
Definition: bf0_ble_ancs.h:262
BLE_ANCS_GET_APP_ATTR_RSP
@ BLE_ANCS_GET_APP_ATTR_RSP
Definition: bf0_ble_ancs.h:85
ble_gap_encrypt_ind_t::conn_idx
uint8_t conn_idx
Connection index.
Definition: bf0_ble_gap.h:1719
BLE_ANCS_EVENT_FLAG_PRE_EXISTING
@ BLE_ANCS_EVENT_FLAG_PRE_EXISTING
Definition: bf0_ble_ancs.h:146
BLE_GAP_ENCRYPT_IND
@ BLE_GAP_ENCRYPT_IND
Definition: bf0_ble_gap.h:160
BLE_ANCS_EVENT_ID_NOTIFICATION_ADDED
@ BLE_ANCS_EVENT_ID_NOTIFICATION_ADDED
Definition: bf0_ble_ancs.h:133
data
uint8_t data[]
Definition: bf0_ble_ancs.h:227
ble_ancs_attr_enable
void ble_ancs_attr_enable(uint8_t attr_index, uint8_t enable, uint16_t len)
Configure notification attribte id and according length.
BLE_ANCS_NOTIFICATION_ATTR_ID_MESSAGE
@ BLE_ANCS_NOTIFICATION_ATTR_ID_MESSAGE
Definition: bf0_ble_ancs.h:169
BLE_ANCS_NOTIFICATION_ATTR_ID_APP_ID
@ BLE_ANCS_NOTIFICATION_ATTR_ID_APP_ID
Definition: bf0_ble_ancs.h:166
BLE_ANCS_NOTIFICATION_ATTR_ID_TITLE
@ BLE_ANCS_NOTIFICATION_ATTR_ID_TITLE
Definition: bf0_ble_ancs.h:167
ble_ancs_noti_attr_t::evt_flag
uint8_t evt_flag
Definition: bf0_ble_ancs.h:258
BLE_ANCS_NOTIFICATION_IND
@ BLE_ANCS_NOTIFICATION_IND
Definition: bf0_ble_ancs.h:84
ble_ancs_get_app_attr
int32_t ble_ancs_get_app_attr(uint8_t *app_id, uint8_t app_id_len)
Acquire app attribute via app ID.
ble_gap_encrypt_ind_t
The structure of BLE_GAP_ENCRYPT_IND.
Definition: bf0_ble_gap.h:1717
ble_ancs_enable
uint8_t ble_ancs_enable(uint8_t conn_idx)
Enable ble ancs profile service, it will search ANCS service from peer device. It should be called af...
ble_ancs_noti_attr_t::value
ble_ancs_attr_value_t * value
Definition: bf0_ble_ancs.h:263
ble_ancs_noti_attr_t
The structure of BLE_ANCS_NOTIFICATION_IND.
Definition: bf0_ble_ancs.h:256
BLE_EVENT_REGISTER
#define BLE_EVENT_REGISTER(func, context)
Macro of siflie ble event handler register.
Definition: bf0_ble_common.h:172