Function assignment
DeviceFunction को supported DeviceOperation पर assign करें।
आवश्यक शर्तें
- Device connected और ready हो
- Device
DevicePhysicalOperationsAPIsupport करता हो - Operation
physicalOperationsMappingमें मौजूद हो
API Reference
Framework
AIBuds.xcframework
Import
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>Protocol की घोषणा
- Swift
- Objective-C
/// 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?
)
}/// The protocol for device physical operations API.
@protocol AIBudsDevicePhysicalOperationsAPI <AIBudsDeviceAPI>
/// 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.
- (void)assignFunction:(enum AIBudsDeviceFunction)function
forPhysicalOperation:(enum AIBudsDeviceOperation)operation
completion:(AIBudsCompletionHandler _Nullable)completion;
@endInstance method
Physical operation को function assign करता है।
- Swift
- Objective-C
/// 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?
)/// 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.
- (void)assignFunction:(enum AIBudsDeviceFunction)function
forPhysicalOperation:(enum AIBudsDeviceOperation)operation
completion:(AIBudsCompletionHandler _Nullable)completion;उपलब्ध parameters
| Parameter | Type | विवरण |
|---|---|---|
function | DeviceFunction | Assign की जाने वाली function। |
operation | DeviceOperation | Function trigger करने वाला physical operation। |
completion | AIBudsCompletionHandler? | Optional completion handler। |
Callback parameters:
| Name | Type | विवरण |
|---|---|---|
success | Bool / BOOL | Assignment सफल हुआ या नहीं। |
error | NSError? | Failure details; सफलता पर nil। |
Return value
यह method सीधे कोई value return नहीं करता।
उपयोग के उदाहरण
- Swift
- Objective-C
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")
}#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
id<AIBudsDevicePhysicalOperationsAPI> device = (id<AIBudsDevicePhysicalOperationsAPI>)self.device;
if ([device conformsToProtocol:@protocol(AIBudsDevicePhysicalOperationsAPI)]) {
[device assignFunction:AIBudsDeviceFunctionPlayPause
forPhysicalOperation:AIBudsDeviceOperationRightDoubleClick
completion:^(BOOL success, NSError *_Nullable error) {
if (!success) {
NSLog(@"Assignment failed: %@", error.localizedDescription);
return;
}
NSLog(@"Function assigned");
}];
}Error handling
success जाँचें और failure details के लिए error उपयोग करें। Completion success बताए बिना local mapping update न करें।
बेहतर तरीके
- Reported mapping से शुरू करें: केवल
physicalOperationsMappingद्वारा reported operations दें। - SDK enums उपयोग करें: Arbitrary integers के बजाय
DeviceOperationऔरDeviceFunctionदें। - Success के बाद refresh करें: Applied configuration दिखाते समय mapping दोबारा पढ़ें।
ध्यान देने योग्य बातें
- API हर call में एक operation को एक function assign करती है।
- SDK
KeyMappingmodel याcustomizeKeyMappingmethod define नहीं करता।