İşlev Atama
Bir DeviceFunction değerini desteklenen bir DeviceOperation değerine atayın.
Ön Koşullar
- Cihaz bağlı ve hazırdır
- Cihaz
DevicePhysicalOperationsAPIprotokolünü destekler - İşlem
physicalOperationsMappingiçinde bulunur
API Referansı
Framework
AIBuds.xcframework
İçe Aktarma
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>Protokol
- 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;
@endÖrnek Yöntemi
Fiziksel bir işleme işlev atar.
- 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;Parametreler
| Parametre | Tür | Açıklama |
|---|---|---|
function | DeviceFunction | Atanacak işlev. |
operation | DeviceOperation | İşlevi tetikleyen fiziksel işlem. |
completion | AIBudsCompletionHandler? | İsteğe bağlı completion handler. |
Callback Parametreleri:
| Ad | Tür | Açıklama |
|---|---|---|
success | Bool / BOOL | Atamanın başarılı olup olmadığı. |
error | NSError? | Hata ayrıntıları; başarılıysa nil. |
Dönüş Değeri
Bu yöntem doğrudan değer döndürmez.
Kullanım Örnekleri
- 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");
}];
}Hata Yönetimi
success değerini denetleyin ve hata ayrıntıları için error kullanın. Completion başarı bildirmeden yerel eşlemeyi güncellemeyin.
En İyi Uygulamalar
- Bildirilen Eşlemeden Başlayın:
physicalOperationsMappingiçinde bildirilen işlemleri sunun. - SDK Enum'larını Kullanın: Rastgele tamsayılar yerine
DeviceOperationveDeviceFunctioniletin. - Başarıdan Sonra Yenileyin: Uygulanan yapılandırmayı gösterirken eşlemeyi yeniden okuyun.
Notlar
- API her çağrıda bir işleme tek bir işlev atar.
- SDK bir
KeyMappingmodeli veyacustomizeKeyMappingyöntemi tanımlamaz.