accessory-setup-kit

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

AccessorySetupKit

AccessorySetupKit

What to open

需查看的内容

  • Use
    accessory-setup-kit/accessorysetupkit.md
    for all API details and key names.
  • Use
    accessory-setup-kit/AccessorySetupKitEverythingBLEDevelopersNeedToKnow.md
    for BLE-specific behavior notes and real-world details.
  • Search within it for: "Discovering and configuring accessories",
    ASAccessorySession
    ,
    ASDiscoveryDescriptor
    ,
    ASPickerDisplayItem
    ,
    ASMigrationDisplayItem
    ,
    ASPickerDisplaySettings
    , and
    ASAccessoryEventType
    .
  • 所有API详情和键名请查看
    accessory-setup-kit/accessorysetupkit.md
  • 有关BLE特定行为说明和实际应用细节,请查看
    accessory-setup-kit/AccessorySetupKitEverythingBLEDevelopersNeedToKnow.md
  • 可在其中搜索以下内容:"Discovering and configuring accessories"、
    ASAccessorySession
    ASDiscoveryDescriptor
    ASPickerDisplayItem
    ASMigrationDisplayItem
    ASPickerDisplaySettings
    ASAccessoryEventType

Workflow

工作流程

  • Identify whether the accessory uses Bluetooth, Wi-Fi, or Wi-Fi Aware and set up matching discovery properties.
  • Declare required Info.plist keys for AccessorySetupKit and any Bluetooth identifiers.
  • Create and activate
    ASAccessorySession
    , then handle events on the provided queue.
  • Present a picker with
    ASPickerDisplayItem
    items that match the accessories you support.
  • Handle
    .accessoryAdded
    to connect to the selected device; handle
    .accessoryRemoved
    and
    .accessoryChanged
    as needed.
  • 确定配件使用的是蓝牙、Wi-Fi还是Wi-Fi Aware,并设置匹配的发现属性。
  • 声明AccessorySetupKit所需的Info.plist键以及任何蓝牙标识符。
  • 创建并激活
    ASAccessorySession
    ,然后在提供的队列上处理事件。
  • 展示包含与你支持的配件匹配的
    ASPickerDisplayItem
    项的选择器。
  • 处理
    .accessoryAdded
    事件以连接到所选设备;根据需要处理
    .accessoryRemoved
    .accessoryChanged
    事件。

Picker guidance

选择器指南

  • A display item must include a descriptor with a Bluetooth identifier or Wi-Fi SSID/SSID prefix.
  • For Bluetooth filters, provide at least a service UUID or company identifier, and optionally a name substring or manufacturer/service data mask pair.
  • To do custom filtering, enable
    filterDiscoveryResults
    and handle
    .accessoryDiscovered
    by creating
    ASDiscoveredDisplayItem
    entries, then call
    updatePicker(showing:completionHandler:)
    .
  • If custom filtering needs unlimited time, set
    discoveryTimeout = .unbounded
    and finish discovery with
    finishPickerDiscovery(completionHandler:)
    .
  • 展示项必须包含带有蓝牙标识符或Wi-Fi SSID/SSID前缀的描述符。
  • 对于蓝牙过滤器,至少提供一个服务UUID或公司标识符,还可选择提供名称子串或制造商/服务数据掩码对。
  • 若要进行自定义过滤,请启用
    filterDiscoveryResults
    并通过创建
    ASDiscoveredDisplayItem
    条目来处理
    .accessoryDiscovered
    事件,然后调用
    updatePicker(showing:completionHandler:)
  • 如果自定义过滤需要无限制时间,请设置
    discoveryTimeout = .unbounded
    ,并调用
    finishPickerDiscovery(completionHandler:)
    来结束发现过程。

Migration and post-setup

迁移与设置后操作

  • Use
    ASMigrationDisplayItem
    to migrate previously-configured accessories into AccessorySetupKit.
  • Use setup and rename options on picker items when the user should rename or finish setup in-app.
  • 使用
    ASMigrationDisplayItem
    将之前配置的配件迁移到AccessorySetupKit中。
  • 当用户需要在应用内重命名或完成设置时,使用选择器项上的设置和重命名选项。

Reminders

注意事项

  • Keep discovery descriptors specific to avoid broad Bluetooth access.
  • For Wi-Fi Aware, set Wi-Fi Aware properties on
    ASDiscoveryDescriptor
    before discovery.
  • Use the session event stream to keep app state in sync with user actions.
  • 保持发现描述符的针对性,以避免广泛的蓝牙访问权限。
  • 对于Wi-Fi Aware,请在开始发现前在
    ASDiscoveryDescriptor
    上设置Wi-Fi Aware属性。
  • 使用会话事件流使应用状态与用户操作保持同步。