본문으로 건너뛰기

기능 할당

DeviceFunction을 지원되는 DeviceOperation에 할당합니다.

사전 요구 사항

  • 기기가 연결되어 사용할 수 있는 상태입니다.
  • 기기가 DevicePhysicalOperationsAPI를 지원합니다.
  • 조작이 physicalOperationsMapping에 포함되어 있습니다.

API 참고

프레임워크

AIBuds.xcframework

가져오기

Swift
import AIBuds

프로토콜

Swift
/// The protocol for device physical operations API.
protocol DevicePhysicalOperationsAPI: DeviceAPI {
    /// Assign a device function to a specific operation.
    ///
    /// - Parameters:
    ///   - function: The ``DeviceFunction`` to be assigned.
    ///   - operation: The ``DeviceOperation`` that will trigger the function.
    ///   - completion: An optional callback invoked when the assignment completes.
    ///     - success: `true` if the assignment succeeded; `false` otherwise.
    ///     - error: An error object explaining the failure, or `nil` on success.
    func assignFunction(
        _ function: DeviceFunction,
        forPhysicalOperation operation: DeviceOperation,
        completion: AIBudsCompletionHandler?
    )
}

인스턴스 메서드

기기 조작에 기능을 할당합니다.

Swift
/// Assign a device function to a specific operation.
///
/// - Parameters:
///   - function: The ``DeviceFunction`` to be assigned.
///   - operation: The ``DeviceOperation`` that will trigger the function.
///   - completion: An optional callback invoked when the assignment completes.
///     - success: `true` if the assignment succeeded; `false` otherwise.
///     - error: An error object explaining the failure, or `nil` on success.
func assignFunction(
    _ function: DeviceFunction,
    forPhysicalOperation operation: DeviceOperation,
    completion: AIBudsCompletionHandler?
)

매개변수

매개변수타입설명
functionDeviceFunction할당할 기능입니다.
operationDeviceOperation기능을 실행할 기기 조작입니다.
completionAIBudsCompletionHandler?선택적 completion handler입니다.

콜백 매개변수:

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

반환 값

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

사용 예제

Swift
import AIBuds

guard let device = device as? DevicePhysicalOperationsAPI else {
    print("Device does not support physical-operation mapping")
    return
}

device.assignFunction(
    .playPause,
    forPhysicalOperation: .rightDoubleClick
) { success, error in
    guard success else {
        print("Assignment failed: \(error?.localizedDescription ?? "Unknown error")")
        return
    }
    print("Function assigned")
}

오류 처리

success를 확인하고 실패 상세 정보는 error에서 확인하세요. completion이 성공을 보고하기 전에는 로컬 매핑을 변경하지 마세요.

권장 사항

  1. 공개된 매핑에서 시작: physicalOperationsMapping이 보고한 조작만 제공하세요.
  2. SDK enum 사용: 임의의 정수 대신 DeviceOperationDeviceFunction을 전달하세요.
  3. 성공 후 갱신: 적용된 설정을 표시할 때 매핑을 다시 읽으세요.

참고

  • API를 한 번 호출할 때 하나의 조작에 하나의 기능을 할당합니다.
  • SDK에는 KeyMapping 모델이나 customizeKeyMapping 메서드가 정의되어 있지 않습니다.