-
Notifications
You must be signed in to change notification settings - Fork 0
Core Physical Operations Assign Functions
Mr.P edited this page Aug 29, 2026
·
2 revisions
Assign a DeviceFunction to a supported DeviceOperation.
- The device is connected and ready
- The device supports
DevicePhysicalOperationsAPI - The operation exists in
physicalOperationsMapping
AIBuds.xcframework
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>/// 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;
@endAssigns a function to a physical operation.
/// 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;| Parameter | Type | Description |
|---|---|---|
function |
DeviceFunction |
The function to assign. |
operation |
DeviceOperation |
The physical operation that triggers the function. |
completion |
AIBudsCompletionHandler? |
Optional completion handler. |
Callback Parameters:
| Name | Type | Description |
|---|---|---|
success |
Bool / BOOL
|
Whether the assignment succeeded. |
error |
NSError? |
Failure details, or nil on success. |
This method returns no value directly.
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");
}];
}Check success and use error for failure details. Do not update a local mapping until the completion reports success.
-
Start from the Published Mapping: Offer operations reported by
physicalOperationsMapping. -
Use SDK Enums: Pass
DeviceOperationandDeviceFunction, not arbitrary integers. - Refresh After Success: Re-read the mapping when presenting the applied configuration.
- The API assigns one function to one operation per call.
- The SDK does not define a
KeyMappingmodel orcustomizeKeyMappingmethod.
AIBuds SDK documentation · Full documentation · API Reference
- Introduction
- Getting Started
- Core Concepts
-
Core Features
- Basic Features
- Device Info
- Find Device
- Physical Operations
- Work Mode
- Work Status
- Wear Detection
- Volume Control
- Music Control
- TWS
- Equalizer
- ANC
- Audio
- Camera
- Remote Camera
- File Import
- Teleprompter
- Segment Navigation
- Live Streaming
- Device Applications
- OTA
- Camera OTA
- Service Auth
- AI Services
- Voice Assistant
- Logging
- Advanced Topics
- Releases
- Troubleshooting