Takma Algılama Durumunu Görüntüleme
Takma algılamanın etkin olup olmadığını ve kulaklıkların hiçbirinin, birinin veya her ikisinin takılı 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
- Swift
- Objective-C
/// The protocol for device wear detection API.
protocol DeviceWearDetectionAPI: DeviceAPI {
/// Indicates whether wear detection is currently enabled
var isWearDetectionEnabled: Bool { get }
/// The current wear status of the device.
var wearStatus: WearStatus { get }
}/// The protocol for device wear detection API.
@protocol AIBudsDeviceWearDetectionAPI <AIBudsDeviceAPI>
/// Indicates whether wear detection is currently enabled
@property(nonatomic, readonly) BOOL isWearDetectionEnabled;
/// The current wear status of the device.
@property(nonatomic, readonly) enum AIBudsWearStatus wearStatus;
@endÖzellikler
| Özellik | Tür | Açıklama |
|---|---|---|
isWearDetectionEnabled | Bool / BOOL | Takma algılamanın o anda etkin olup olmadığı. |
wearStatus | WearStatus | Güncel sol/sağ takılma durumu. |
Takılma Durumu Değerleri
| Swift | Objective-C | Anlamı |
|---|---|---|
.unknown | AIBudsWearStatusUnknown | Takılma durumu bilinmiyor. |
.notWearing | AIBudsWearStatusNotWearing | İki taraf da takılı değil. |
.leftWearing | AIBudsWearStatusLeftWearing | Yalnızca sol taraf takılı. |
.rightWearing | AIBudsWearStatusRightWearing | Yalnızca sağ taraf takılı. |
.bothWearing | AIBudsWearStatusBothWearing | İki taraf da takılı. |
Kullanım Örnekleri
- Swift
- Objective-C
import AIBuds
guard let device = device as? DeviceWearDetectionAPI else {
print("Device does not support wear detection")
return
}
print("Wear detection enabled: \(device.isWearDetectionEnabled)")
switch device.wearStatus {
case .unknown:
print("Wear state is unknown")
case .notWearing:
print("Neither side is worn")
case .leftWearing:
print("Only the left side is worn")
case .rightWearing:
print("Only the right side is worn")
case .bothWearing:
print("Both sides are worn")
@unknown default:
print("Unsupported wear-state value")
}#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
id<AIBudsDeviceWearDetectionAPI> device = (id<AIBudsDeviceWearDetectionAPI>)self.device;
if ([device conformsToProtocol:@protocol(AIBudsDeviceWearDetectionAPI)]) {
NSLog(@"Wear detection enabled: %@", device.isWearDetectionEnabled ? @"YES" : @"NO");
NSLog(@"Wear status raw value: %ld", (long)device.wearStatus);
}Hata Yönetimi
Bunlar eşzamanlı durum özellikleridir ve hata döndürmez. Desteklenmeyen protokolü ve .unknown değerini açıkça işleyin. Güncel durum okunduktan sonra değişebilir.
En İyi Uygulamalar
- Etkinlik ile Takılma Durumunu Ayırın:
falseve.notWearingfarklı kavramları tanımlar. - Güncellemeleri İzleyin: Arayüz güncel kalacaksa
didWearDetectionEnabledChangedvedidWearStatusChangedyöntemlerini uygulayın. - Arayüzü Ana Thread'de Güncelleyin: Delegate kaynaklı değişiklikleri gerektiğinde ana kuyruğa yönlendirin.
Notlar
- SDK,
getWearDetectionSwitchStatusveyaResulttabanlı sorgular yerine özellikler sunar. .unknown, “takılı değil” olarak gösterilmemelidir.