メインコンテンツまでスキップ

装着検出の対応状況

デバイスが装着検出に対応しているか、また設定を変更できるかを確認します。

前提条件

  • デバイスが接続済みで、操作可能な状態であること。
  • デバイスが DeviceWearDetectionAPI に準拠していること。

API リファレンス

フレームワーク

AIBuds.xcframework

インポート

Swift
import AIBuds

プロトコル

対応状況は DeviceWearDetectionAPI のプロパティとして公開されています。

Swift
/// The protocol for device wear detection API.
protocol DeviceWearDetectionAPI: DeviceAPI {
    /// The wear-detection capabilities supported by the device
    var wearDetectionCapability: WearDetectionCapability { get }
}

プロパティ

プロパティ説明
wearDetectionCapabilityWearDetectionCapabilityデバイスが現在通知している対応状況。

対応状況の値

SwiftObjective-C意味
.noneAIBudsWearDetectionCapabilityNone非対応。
.supportedNotConfigurableAIBudsWearDetectionCapabilitySupportedNotConfigurable対応していますが、設定は変更できません。
.supportedAndConfigurableAIBudsWearDetectionCapabilitySupportedAndConfigurable対応しており、設定も変更できます。

使用例

Swift
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")
}

エラー処理

このプロパティには完了ハンドラーがありません。プロトコル非対応と、将来追加される未知の列挙値を処理してください。.none は通信エラーではなく、有効な対応状況の値です。

ベストプラクティス

  1. 設定前に確認する: 有効/無効の操作 UI を表示する前に、対応状況を確認します。
  2. 対応状況を区別する: 「設定不可」を「非対応」と同一視しないでください。
  3. 将来の値に備える: Swift で列挙値を分岐する場合は @unknown default を使用します。

注意事項

  • この API は同期プロパティの読み取りであり、非同期の getWearDetectionSupport メソッドではありません。
  • SDK Demo では、このプロパティを基に設定 UI を表示するか判断します。