Takma Algılamayı Ayarlama
Cihaz yapılandırılabilir destek bildirdiğinde takma algılamayı etkinleştirin veya devre dışı bırakın.
Ön Koşullar
- Cihaz bağlı ve hazırdır.
- Cihaz
DeviceWearDetectionAPIprotokolüne uyar. wearDetectionCapability,.supportedAndConfigurabledeğerindedir.
API Referansı
Framework
AIBuds.xcframework
İçe Aktarma
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>Protokol
Yöntem DeviceWearDetectionAPI tarafından tanımlanır.
- Swift
- Objective-C
/// The protocol for device wear detection API.
protocol DeviceWearDetectionAPI: DeviceAPI {
/// Enable or disable wear-detection functionality
/// - Parameters:
/// - enabled: Whether to enable wear detection
/// - completion: A closure that is called when the operation completes.
/// - success: `true` if the operation was successful; otherwise `false`.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
func setWearDetection(
enabled: Bool,
completion: AIBudsCompletionHandler?
)
}/// The protocol for device wear detection API.
@protocol AIBudsDeviceWearDetectionAPI <AIBudsDeviceAPI>
/// Enable or disable wear-detection functionality
/// - Parameters:
/// - enabled: Whether to enable wear detection
/// - completion: A closure that is called when the operation completes.
/// - success: `true` if the operation was successful; otherwise `false`.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the
/// operation was successful.
- (void)setWearDetectionEnabled:(BOOL)enabled
completion:(AIBudsCompletionHandler _Nullable)completion;
@endÖrnek Yöntemi
Takma algılamayı etkinleştirir veya devre dışı bırakır.
API ReferansındasetWearDetection öğesini açın.
- Swift
- Objective-C
/// Enable or disable wear-detection functionality
/// - Parameters:
/// - enabled: Whether to enable wear detection
/// - completion: A closure that is called when the operation completes.
/// - success: `true` if the operation was successful; otherwise `false`.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
func setWearDetection(
enabled: Bool,
completion: AIBudsCompletionHandler?
)/// Enable or disable wear-detection functionality
/// - Parameters:
/// - enabled: Whether to enable wear detection
/// - completion: A closure that is called when the operation completes.
/// - success: `true` if the operation was successful; otherwise `false`.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the
/// operation was successful.
- (void)setWearDetectionEnabled:(BOOL)enabled
completion:(AIBudsCompletionHandler _Nullable)completion;Parametreler
| Parametre | Tür | Açıklama |
|---|---|---|
enabled | Bool / BOOL | Takma algılamayı etkinleştirmek için true/YES; devre dışı bırakmak için aksi değer. |
completion | AIBudsCompletionHandler? | İşlem tamamlandığında çağrılan isteğe bağlı completion handler. |
Callback Parametreleri:
| Ad | Tür | Açıklama |
|---|---|---|
success | Bool / BOOL | İşlemin 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? DeviceWearDetectionAPI else {
print("Device does not support wear detection")
return
}
guard device.wearDetectionCapability == .supportedAndConfigurable else {
print("Wear detection is not configurable")
return
}
device.setWearDetection(enabled: true) { success, error in
guard success else {
print("Failed to enable wear detection: \(error?.localizedDescription ?? "Unknown error")")
return
}
print("Wear detection enabled")
}#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
id<AIBudsDeviceWearDetectionAPI> device = (id<AIBudsDeviceWearDetectionAPI>)self.device;
if (![device conformsToProtocol:@protocol(AIBudsDeviceWearDetectionAPI)]) {
return;
}
if (device.wearDetectionCapability != AIBudsWearDetectionCapabilitySupportedAndConfigurable) {
NSLog(@"Wear detection is not configurable");
return;
}
[device
setWearDetectionEnabled:YES
completion:^(BOOL success, NSError *_Nullable error) {
if (!success) {
NSLog(@"Failed to enable wear detection: %@", error.localizedDescription);
return;
}
NSLog(@"Wear detection enabled");
}];Hata Yönetimi
Yerel arayüzü güncellemeden önce success değerini denetleyin ve hata ayrıntıları için error kullanın. Yetenek .none veya .supportedNotConfigurable olduğunda yöntemi çağırmayın.
En İyi Uygulamalar
- Yeteneği Doğrulayın: Komutu göndermeden önce
.supportedAndConfigurabledeğerini şart koşun. - Gereksiz Komutlardan Kaçının: Önce istenen değeri
isWearDetectionEnabledile karşılaştırın. - Başarıdan Sonra Yenileyin: Uygulanan durumu göstermeden önce güncel özelliği okuyun veya
didWearDetectionEnabledChangedolayını bekleyin.
Notlar
- SDK Demo'su takma algılamayı değiştirmeden önce aynı yetenek denetimini yapar.
- Yöntem otomatik müzik duraklatma veya sürdürme davranışı tanımlamaz.