mcpField
C
corebluetooth

corebluetooth

github.com/nonameplum开发1747 次安装13 周前更新
代码仓库

关于 corebluetooth

面向 Apple Core Bluetooth 开发的参考技能,涵盖中央设备与外围设备角色、操作流程、API 查询及生命周期限制,帮助开发者按角色规划 BLE 操作并遵循相关实践。

主要功能

  1. 01中央设备工作流指南
  2. 02外围设备工作流指南
  3. 03BLE API 与符号查询
  4. 04后台处理与状态恢复指南
  5. 05角色相关的最佳实践

适用场景

  1. 01构建扫描并连接外围设备的应用
  2. 02配置应用作为外围设备广播
  3. 03处理蓝牙后台行为与状态恢复

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/nonameplum/agent-skills --skill corebluetooth

安装后在 Claude Code 中输入/corebluetooth确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

AboutCoreBluetooth.md
BestPracticesforInteractingwithaRemotePeripheralDevice.md
BestPracticesforSettingUpYourLocalDeviceasaPeripheral.md
BluetoothStateRestorationAppReaunchRules.md
corebluetooth.md
CoreBluetoothBackgroundProcessingforiOSApps.md
CoreBluetoothOverview.md
PerformingCommonCentralRoleTasks.md
PerformingCommonPeripheralRoleTasks.md

详细介绍

Core Bluetooth

打开什么内容

  • 使用 corebluetooth/AboutCoreBluetooth.md 和 corebluetooth/CoreBluetoothOverview.md 了解概念和角色定位。
  • 使用 corebluetooth/PerformingCommonCentralRoleTasks.md 了解分步执行的中心角色工作流。
  • 使用 corebluetooth/PerformingCommonPeripheralRoleTasks.md 了解分步执行的外围设备角色工作流。
  • 使用 corebluetooth/BestPracticesforInteractingwithaRemotePeripheralDevice.md 和 corebluetooth/BestPracticesforSettingUpYourLocalDeviceasaPeripheral.md 了解常见问题和最佳实践。
  • 使用 corebluetooth/CoreBluetoothBackgroundProcessingforiOSApps.md 了解后台模式和生命周期限制。
  • 使用 corebluetooth/BluetoothStateRestorationAppReaunchRules.md 了解状态恢复时的应用重新启动规则。
  • 使用 corebluetooth/corebluetooth.md 快速查阅 API 和查找符号。

工作流

  • 确定应用是充当中心设备、外围设备,还是两者兼任。
  • 等待管理器状态变为 poweredOn 后再执行 BLE 操作。
  • 遵循相应角色的检查清单,确保发现和连接顺序正确。
  • 首先查看相应角色的任务指南和最佳实践;准确的方法签名请查阅 API 参考。

中心设备检查清单

  1. 创建带有委托对象和队列的 CBCentralManager。
  2. 处理 centralManagerDidUpdateState(_:),并确保仅在状态为 .poweredOn 时扫描。
  3. 使用 scanForPeripherals(withServices:options:) 扫描,并在找到目标后停止扫描。
  4. 连接设备,设置 CBPeripheral 委托对象,然后发现服务和特征。
  5. 按需读取、写入特征,或订阅特征通知。

外围设备检查清单

  1. 创建带有委托对象和队列的 CBPeripheralManager。
  2. 等待状态变为 .poweredOn。
  3. 定义服务和特征,然后将其添加到管理器。
  4. 使用服务 UUID 和可选的本地名称开始广播。
  5. 响应读取和写入请求;向已订阅的中心设备发布更新。

提醒

  • 保留发现的 CBPeripheral 实例,避免其被释放。
  • 流式传输数据时使用通知;仅当 canSendWriteWithoutResponse 为 true 时才使用无响应写入。
  • 仅当用例不适合使用 GATT 特征时才使用 L2CAP。

评论

支持 Markdown