본문으로 건너뛰기

착용 감지 설정

기기가 설정 가능한 지원 수준을 보고하는 경우 착용 감지를 켜거나 끕니다.

사전 요구 사항

  • 기기가 연결되어 사용할 수 있는 상태입니다.
  • 기기가 DeviceWearDetectionAPI를 준수합니다.
  • wearDetectionCapability.supportedAndConfigurable입니다.

API 참고

프레임워크

AIBuds.xcframework

가져오기

Swift
import AIBuds

프로토콜

이 메서드는 DeviceWearDetectionAPI에 정의되어 있습니다.

Swift
/// The protocol for device wear detection API.
protocol DeviceWearDetectionAPI: DeviceAPI {
    /// Enable or disable wear-detection functionality
    /// - Parameters:
    ///   - enabled: Whether to enable wear detection
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func setWearDetection(
        enabled: Bool,
        completion: AIBudsCompletionHandler?
    )
}

인스턴스 메서드

착용 감지를 켜거나 끕니다.

API 참고에서 setWearDetection을 확인하세요.
Swift
/// Enable or disable wear-detection functionality
/// - Parameters:
///   - enabled: Whether to enable wear detection
///   - completion: A closure that is called when the operation completes.
///     - success: `true` if the operation was successful; otherwise `false`.
///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
func setWearDetection(
    enabled: Bool,
    completion: AIBudsCompletionHandler?
)

매개변수

매개변수타입설명
enabledBool / BOOL착용 감지를 켜려면 true/YES, 끄려면 그 외 값을 사용합니다.
completionAIBudsCompletionHandler?작업이 끝날 때 호출되는 선택적 completion handler입니다.

콜백 매개변수:

이름타입설명
successBool / BOOL작업 성공 여부입니다.
errorNSError?실패 상세 정보이며 성공하면 nil입니다.

반환 값

이 메서드는 값을 직접 반환하지 않습니다.

사용 예제

Swift
import AIBuds

guard let device = device as? DeviceWearDetectionAPI else {
    print("Device does not support wear detection")
    return
}

guard device.wearDetectionCapability == .supportedAndConfigurable else {
    print("Wear detection is not configurable")
    return
}

device.setWearDetection(enabled: true) { success, error in
    guard success else {
        print("Failed to enable wear detection: \(error?.localizedDescription ?? "Unknown error")")
        return
    }
    print("Wear detection enabled")
}

오류 처리

로컬 UI를 변경하기 전에 success를 확인하고 실패 상세 정보는 error에서 확인하세요. 지원 수준이 .none 또는 .supportedNotConfigurable이면 이 메서드를 호출하지 마세요.

권장 사항

  1. 지원 수준 검증: 명령을 보내기 전에 .supportedAndConfigurable인지 확인하세요.
  2. 중복 명령 방지: 먼저 요청 값과 isWearDetectionEnabled를 비교하세요.
  3. 성공 후 갱신: 적용 상태를 표시하기 전에 현재 속성을 읽거나 didWearDetectionEnabledChanged를 기다리세요.

참고

  • SDK Demo도 착용 감지를 켜거나 끄기 전에 같은 지원 수준 검사를 수행합니다.
  • 이 메서드는 음악의 자동 일시 정지 또는 재개 동작을 정의하지 않습니다.