मुख्य कंटेंट तक स्किप करें

Function assignment

DeviceFunction को supported DeviceOperation पर assign करें।

आवश्यक शर्तें

  • Device connected और ready हो
  • Device DevicePhysicalOperationsAPI support करता हो
  • Operation physicalOperationsMapping में मौजूद हो

API Reference

Framework

AIBuds.xcframework

Import

Swift
import AIBuds

Protocol की घोषणा

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?
    )
}

Instance method

Physical operation को function assign करता है।

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?
)

उपलब्ध parameters

ParameterTypeविवरण
functionDeviceFunctionAssign की जाने वाली function।
operationDeviceOperationFunction trigger करने वाला physical operation।
completionAIBudsCompletionHandler?Optional completion handler।

Callback parameters:

NameTypeविवरण
successBool / BOOLAssignment सफल हुआ या नहीं।
errorNSError?Failure details; सफलता पर nil

Return value

यह method सीधे कोई value return नहीं करता।

उपयोग के उदाहरण

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

Error handling

success जाँचें और failure details के लिए error उपयोग करें। Completion success बताए बिना local mapping update न करें।

बेहतर तरीके

  1. Reported mapping से शुरू करें: केवल physicalOperationsMapping द्वारा reported operations दें।
  2. SDK enums उपयोग करें: Arbitrary integers के बजाय DeviceOperation और DeviceFunction दें।
  3. Success के बाद refresh करें: Applied configuration दिखाते समय mapping दोबारा पढ़ें।

ध्यान देने योग्य बातें

  • API हर call में एक operation को एक function assign करती है।
  • SDK KeyMapping model या customizeKeyMapping method define नहीं करता।