Takma Algılama Yeteneğini Görüntüleme
Cihazın takma algılamayı destekleyip desteklemediğini ve özelliğin yapılandırılabilir olup olmadığını okuyun.
Ön Koşullar
- Cihaz bağlı ve hazırdır.
- Cihaz
DeviceWearDetectionAPIprotokolüne uyar.
API Referansı
Framework
AIBuds.xcframework
İçe Aktarma
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>Protokol
Yetenek, DeviceWearDetectionAPI protokolünün bir özelliğidir.
- Swift
- Objective-C
/// The protocol for device wear detection API.
protocol DeviceWearDetectionAPI: DeviceAPI {
/// The wear-detection capabilities supported by the device
var wearDetectionCapability: WearDetectionCapability { get }
}/// The protocol for device wear detection API.
@protocol AIBudsDeviceWearDetectionAPI <AIBudsDeviceAPI>
/// The wear-detection capabilities supported by the device
@property(nonatomic, readonly) enum AIBudsWearDetectionCapability wearDetectionCapability;
@endÖzellikler
| Özellik | Tür | Açıklama |
|---|---|---|
wearDetectionCapability | WearDetectionCapability | Cihazın bildirdiği güncel yetenek. |
Desteklenen Değerler
| Swift | Objective-C | Anlamı |
|---|---|---|
.none | AIBudsWearDetectionCapabilityNone | Desteklenmiyor. |
.supportedNotConfigurable | AIBudsWearDetectionCapabilitySupportedNotConfigurable | Destekleniyor ancak yapılandırılamıyor. |
.supportedAndConfigurable | AIBudsWearDetectionCapabilitySupportedAndConfigurable | Destekleniyor ve yapılandırılabiliyor. |
Kullanım Örnekleri
- Swift
- Objective-C
import AIBuds
guard let device = device as? DeviceWearDetectionAPI else {
print("Wear detection is not exposed by this device")
return
}
switch device.wearDetectionCapability {
case .none:
print("Wear detection is not supported")
case .supportedNotConfigurable:
print("Wear detection is supported but not configurable")
case .supportedAndConfigurable:
print("Wear detection is supported and configurable")
@unknown default:
print("Unknown wear-detection capability")
}#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
id<AIBudsDeviceWearDetectionAPI> device = (id<AIBudsDeviceWearDetectionAPI>)self.device;
if (![device conformsToProtocol:@protocol(AIBudsDeviceWearDetectionAPI)]) {
NSLog(@"Wear detection is not exposed by this device");
return;
}
switch (device.wearDetectionCapability) {
case AIBudsWearDetectionCapabilityNone:
NSLog(@"Wear detection is not supported");
break;
case AIBudsWearDetectionCapabilitySupportedNotConfigurable:
NSLog(@"Wear detection is supported but not configurable");
break;
case AIBudsWearDetectionCapabilitySupportedAndConfigurable:
NSLog(@"Wear detection is supported and configurable");
break;
}Hata Yönetimi
Bu özelliğin completion handler'ı yoktur. Protokol uyumsuzluğunu ve gelecekteki bilinmeyen enum değerlerini işleyin. .none geçerli bir yetenek değeridir; aktarım hatası olarak yorumlamayın.
En İyi Uygulamalar
- Yapılandırmadan Önce Okuyun: Etkinleştirme denetimini göstermeden önce yeteneği denetleyin.
- Tüm Yetenek Düzeylerini Koruyun: “Yapılandırılamıyor” ile “desteklenmiyor” durumlarını birleştirmeyin.
- Gelecekteki Değerleri İşleyin: Swift'te enum üzerinde switch yaparken
@unknown defaultkullanın.
Notlar
- Bu API eşzamanlı özellik okumasıdır; eşzamansız
getWearDetectionSupportyöntemi değildir. - SDK Demo'su yapılandırma denetimlerinin gösterilip gösterilmeyeceğine bu özellikle karar verir.