这个页面的 最新开发版本 可能比这个发布的 2.1.0rc1 版本新。

Peripheral ANCS client

概述

ANCS 示例实现 Apple 通知中心服务客户端。此客户端接收 iOS 通知,因此是通知使用者。 它可以与通知提供程序连接,通常是 iPhone 或其他一些 Apple 设备。

当示例连接到通知提供程序时,它会在 CONSOLE 上接收并打印通知。通知提供 positive 和 negative 操作,具体取决于发送通知的应用程序。 例如,来电通知通常对应应答呼叫的 positive 操作和拒绝呼叫对应的 negative 操作相关联。 收到通知后,可用操作(positive 和 negative)由 CONSOLE 上的标志指示。 该示例可以在控制台上执行 positive 或 negative 操作(cli 命令)作为对通知的响应。 有关 ancs 的更多信息,请参阅:[规范] (https://developer.apple.com/library/archive/documentation/CoreBluetooth/Reference/AppleNotificationCenterServiceSpecification/Specification/Specification.html)

环境要求

  • 支持 BLE 功能的开发板

  • 提供 ANCS Server 服务的设备(iPhone 或者 Apple 设备).

用户指令(cli commands)

read_notify:
  • 读取并打印最新的通知消息.

read_notify_next:
  • 读取并打印在一条通知消息.

read_appl:
  • 读取并打印当前通知的应用程序信息.

action_positive:
  • 执行 positive 操作.

action_negative:
  • 执行 negative 操作.

编译和运行

示例位置:

examples/bluetooth/peripheral_ancs

编译、烧录等操作请参考:[快速入门](https://doc.winnermicro.net/w800/zh_CN/2.1.0rc1/get_started/index.html)

运行结果

[I] (2) main: ver: 0.9.0 build at Sep 11 2024 17:59:33

[I] (2) ancs: Starting Apple Notification Center Service client

[I] (24) bt: LE SC enabled
[I] (152) bt: No ID address. App must call settings_load()
[I] (156) bt: Identity: 28:6D:CD:68:D7:99 (public)
[I] (156) bt: HCI: version 4.2 (0x08) revision 0x0709, manufacturer 0x070c
[I] (156) bt: LMP: version 4.2 (0x08) subver 0x0709
[W] (156) bt: Set privacy mode command is not supported
[I] (160) ancs: Advertising successfully started

测试

  1. 下载固件.

  2. 在 iOS 设备的蓝牙设置菜单,选择 WM ANCS 设备并连接,根据提示完成配对流程。

  3. 请注意,iOS notification (iOS 通知) 选项卡中显示的通知也显示在示例中的 CONSOLE 上。

  4. 输入 read_notify 以检索通知属性,并观察您是否收到上次收到的通知的应用程序标识符等信息。 例如,如果您从日历应用程序收到通知并请求应用程序标识符,则它是“com.apple.mobilecal”。

  5. read_appl 检索应用程序属性,并观察您是否从上一步收到应用程序标识符的显示名称。 例如,请求 “com.apple.mobilecal” 的应用程序属性将生成 “Calendar”。

  6. 如果通知具有positive或negative操作的标志,请分别使用 action_positiveaction_negative 输入通知操作。