TWS デバイスの識別
現在の SDK スナップショットからデバイスの TWS 識別情報を読み取ります。
前提条件
DeviceConvertibleインスタンスを取得済みであること。- デバイスが
DeviceTWSAPIに準拠していること。
API Reference
フレームワーク
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要求ではありません。 - TWS のペアリングは管理しません。