corebluetooth

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Core Bluetooth

Core Bluetooth

What to open

打开哪些文档

  • Use
    corebluetooth/AboutCoreBluetooth.md
    and
    corebluetooth/CoreBluetoothOverview.md
    for concepts and role orientation.
  • Use
    corebluetooth/PerformingCommonCentralRoleTasks.md
    for step-by-step central workflows.
  • Use
    corebluetooth/PerformingCommonPeripheralRoleTasks.md
    for step-by-step peripheral workflows.
  • Use
    corebluetooth/BestPracticesforInteractingwithaRemotePeripheralDevice.md
    and
    corebluetooth/BestPracticesforSettingUpYourLocalDeviceasaPeripheral.md
    for pitfalls and best practices.
  • Use
    corebluetooth/CoreBluetoothBackgroundProcessingforiOSApps.md
    for background modes and lifecycle constraints.
  • Use
    corebluetooth/BluetoothStateRestorationAppReaunchRules.md
    for state restoration app relaunch rules.
  • Use
    corebluetooth/corebluetooth.md
    for API quick maps and symbol lookup.
  • 如需了解概念与角色定位,请查看
    corebluetooth/AboutCoreBluetooth.md
    corebluetooth/CoreBluetoothOverview.md
  • 如需分步了解中心设备工作流,请查看
    corebluetooth/PerformingCommonCentralRoleTasks.md
  • 如需分步了解外设工作流,请查看
    corebluetooth/PerformingCommonPeripheralRoleTasks.md
  • 如需了解注意事项与最佳实践,请查看
    corebluetooth/BestPracticesforInteractingwithaRemotePeripheralDevice.md
    corebluetooth/BestPracticesforSettingUpYourLocalDeviceasaPeripheral.md
  • 如需了解后台模式与生命周期限制,请查看
    corebluetooth/CoreBluetoothBackgroundProcessingforiOSApps.md
  • 如需了解状态恢复下的应用重启规则,请查看
    corebluetooth/BluetoothStateRestorationAppReaunchRules.md
  • 如需API快速映射与符号查找,请查看
    corebluetooth/corebluetooth.md

Workflow

工作流

  • Identify whether the app acts as a central, a peripheral, or both.
  • Wait for the manager state to be
    poweredOn
    before issuing BLE operations.
  • Follow the role checklist to keep discovery and connection order correct.
  • Open the role task guide and best practices first; use the API reference for exact signatures.
  • 确定应用将作为中心设备、外设,还是同时承担两种角色。
  • 在执行BLE操作前,需等待管理器状态变为
    poweredOn
  • 遵循角色检查清单,确保发现与连接顺序正确。
  • 先查看角色任务指南与最佳实践;如需确切签名,请参考API文档。

Central checklist

中心设备检查清单

  1. Create a
    CBCentralManager
    with a delegate and queue.
  2. Handle
    centralManagerDidUpdateState(_:)
    and gate scanning on
    .poweredOn
    .
  3. Scan with
    scanForPeripherals(withServices:options:)
    and stop when the target is found.
  4. Connect, set the
    CBPeripheral
    delegate, and discover services and characteristics.
  5. Read, write, or subscribe to characteristic notifications as needed.
  1. 创建带有代理与队列的
    CBCentralManager
  2. 处理
    centralManagerDidUpdateState(_:)
    方法,仅在状态为
    .poweredOn
    时执行扫描。
  3. 使用
    scanForPeripherals(withServices:options:)
    进行扫描,找到目标设备后停止扫描。
  4. 连接设备,设置
    CBPeripheral
    代理,然后发现服务与特征。
  5. 根据需要读取、写入或订阅特征通知。

Peripheral checklist

外设检查清单

  1. Create a
    CBPeripheralManager
    with a delegate and queue.
  2. Wait for the state to become
    .poweredOn
    .
  3. Define services and characteristics, then add them to the manager.
  4. Start advertising with service UUIDs and optional local name.
  5. Respond to read and write requests; publish updates to subscribed centrals.
  1. 创建带有代理与队列的
    CBPeripheralManager
  2. 等待状态变为
    .poweredOn
  3. 定义服务与特征,然后将其添加至管理器。
  4. 使用服务UUID与可选本地名称开始广播。
  5. 响应读、写请求;向已订阅的中心设备发布更新。

Reminders

注意事项

  • Retain discovered
    CBPeripheral
    instances to keep them alive.
  • Use notifications for streaming data; use write-without-response only when
    canSendWriteWithoutResponse
    is true.
  • Use L2CAP only for use cases that do not fit GATT characteristics.
  • 需保留已发现的
    CBPeripheral
    实例,以维持其活跃状态。
  • 流式数据请使用通知;仅当
    canSendWriteWithoutResponse
    为true时,才可使用无响应写入。
  • 仅当GATT特征无法满足需求时,才使用L2CAP。