跳到主要内容

识别 TWS 设备

从当前 SDK 快照读取设备的 TWS 标识。

前置条件

  • 已获取 DeviceConvertible 实例。
  • 设备支持 DeviceTWSAPI

API 参考

框架

AIBuds.xcframework

导入

Swift
import AIBuds

协议

Swift
/// The protocol for device True Wireless Stereo (TWS) related API.
protocol DeviceTWSAPI: DeviceAPI {
    /// Indicates whether the device is a True Wireless Stereo (TWS) device.
    var isTws: Bool { get }
}

属性

属性类型描述
isTwsBool / BOOL设备是否将自身标识为 TWS 设备。

使用示例

Swift
import AIBuds

guard let device = device as? DeviceTWSAPI else {
    print("TWS information is unavailable")
    return
}

print(device.isTws ? "TWS device" : "Not a TWS device")

错误处理

该属性没有完成回调。请将协议不支持与有效的 false 值分开处理。

最佳实践

  1. 不要混淆不支持与 false:协议不符合不等同于 isTws == false
  2. 单独使用连接状态:仅在需要连接状态时读取 isTwsConnected

注意事项

  • 该 API 是同步属性读取,不是 getTWSSupport 请求。
  • 该 API 不管理 TWS 配对。