装着検出の対応状況
デバイスが装着検出に対応しているか、また設定を変更できるかを確認します。
前提条件
- デバイスが接続済みで、操作可能な状態であること。
- デバイスが
DeviceWearDetectionAPIに準拠していること。
API リファレンス
フレームワーク
AIBuds.xcframework
インポート
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>プロトコル
対応状況は DeviceWearDetectionAPI のプロパティとして公開されています。
- Swift
- Objective-C
/// The protocol for device wear detection API.
protocol DeviceWearDetectionAPI: DeviceAPI {
/// The wear-detection capabilities supported by the device
var wearDetectionCapability: WearDetectionCapability { get }
}/// The protocol for device wear detection API.
@protocol AIBudsDeviceWearDetectionAPI <AIBudsDeviceAPI>
/// The wear-detection capabilities supported by the device
@property(nonatomic, readonly) enum AIBudsWearDetectionCapability wearDetectionCapability;
@endプロパティ
| プロパティ | 型 | 説明 |
|---|---|---|
wearDetectionCapability | WearDetectionCapability | デバイスが現在通知している対応状況。 |
対応状況の値
| Swift | Objective-C | 意味 |
|---|---|---|
.none | AIBudsWearDetectionCapabilityNone | 非対応。 |
.supportedNotConfigurable | AIBudsWearDetectionCapabilitySupportedNotConfigurable | 対応していますが、設定は変更できません。 |
.supportedAndConfigurable | AIBudsWearDetectionCapabilitySupportedAndConfigurable | 対応しており、設定も変更できます。 |
使用例
- Swift
- Objective-C
import AIBuds
guard let device = device as? DeviceWearDetectionAPI else {
print("Wear detection is not exposed by this device")
return
}
switch device.wearDetectionCapability {
case .none:
print("Wear detection is not supported")
case .supportedNotConfigurable:
print("Wear detection is supported but not configurable")
case .supportedAndConfigurable:
print("Wear detection is supported and configurable")
@unknown default:
print("Unknown wear-detection capability")
}#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
id<AIBudsDeviceWearDetectionAPI> device = (id<AIBudsDeviceWearDetectionAPI>)self.device;
if (![device conformsToProtocol:@protocol(AIBudsDeviceWearDetectionAPI)]) {
NSLog(@"Wear detection is not exposed by this device");
return;
}
switch (device.wearDetectionCapability) {
case AIBudsWearDetectionCapabilityNone:
NSLog(@"Wear detection is not supported");
break;
case AIBudsWearDetectionCapabilitySupportedNotConfigurable:
NSLog(@"Wear detection is supported but not configurable");
break;
case AIBudsWearDetectionCapabilitySupportedAndConfigurable:
NSLog(@"Wear detection is supported and configurable");
break;
}エラー処理
このプロパティには完了ハンドラーがありません。プロトコル非対応と、将来追加される未知の列挙値を処理してください。.none は通信エラーではなく、有効な対応状況の値です。
ベストプラクティス
- 設定前に確認する: 有効/無効の操作 UI を表示する前に、対応状況を確認します。
- 対応状況を区別する: 「設定不可」を「非対応」と同一視しないでください。
- 将来の値に備える: Swift で列挙値を分岐する場合は
@unknown defaultを使用します。
注意事項
- この API は同期プロパティの読み取りであり、非同期の
getWearDetectionSupportメソッドではありません。 - SDK Demo では、このプロパティを基に設定 UI を表示するか判断します。