识别 TWS 设备
从当前 SDK 快照读取设备的 TWS 标识。
前置条件
- 已获取
DeviceConvertible实例。 - 设备支持
DeviceTWSAPI。
API 参考
框架
AIBuds.xcframework
导入
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>协议
- Swift
- Objective-C
/// 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 }
}/// The protocol for device True Wireless Stereo (TWS) related API.
@protocol AIBudsDeviceTWSAPI <AIBudsDeviceAPI>
/// Indicates whether the device is a True Wireless Stereo (TWS) device.
@property(nonatomic, readonly) BOOL isTws;
@end属性
| 属性 | 类型 | 描述 |
|---|---|---|
isTws | Bool / BOOL | 设备是否将自身标识为 TWS 设备。 |
使用示例
- Swift
- Objective-C
import AIBuds
guard let device = device as? DeviceTWSAPI else {
print("TWS information is unavailable")
return
}
print(device.isTws ? "TWS device" : "Not a TWS device")id<AIBudsDeviceTWSAPI> device = (id<AIBudsDeviceTWSAPI>)self.device;
if ([device conformsToProtocol:@protocol(AIBudsDeviceTWSAPI)]) {
NSLog(@"%@", device.isTws ? @"TWS device" : @"Not a TWS device");
}错误处理
该属性没有完成回调。请将协议不支持与有效的 false 值分开处理。
最佳实践
- 不要混淆不支持与 false:协议不符合不等同于
isTws == false。 - 单独使用连接状态:仅在需要连接状态时读取
isTwsConnected。
注意事项
- 该 API 是同步属性读取,不是
getTWSSupport请求。 - 该 API 不管理 TWS 配对。