Çalışma Durumunu Okuma
Cihazın güncel WorkState değerini okuyun.
Ön Koşullar
- Cihaz bağlıdır
- Cihaz
DeviceWorkStateAPIprotokolünü destekler
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 work state API.
protocol DeviceWorkStateAPI: DeviceAPI {
/// The current working state of the device.
var workState: WorkState { get }
}/// The protocol for device work state API.
@protocol AIBudsDeviceWorkStateAPI <AIBudsDeviceAPI>
/// The current working state of the device.
@property(nonatomic, readonly) enum AIBudsWorkState workState;
@endÖzellikler
| Özellik | Tür | Açıklama |
|---|---|---|
workState | WorkState / AIBudsWorkState | Cihazın bildirdiği güncel çalışma durumu. |
Dönüş Değeri
workState, eşzamanlı ve salt okunur bir özelliktir; birleşik bir durum modeli döndürmez.
Kullanım Örnekleri
- Swift
- Objective-C
import AIBuds
guard let device = device as? DeviceWorkStateAPI else {
print("Device does not expose a work state")
return
}
let state = device.workState
print("Current work state: \(state.description)")#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
id<AIBudsDeviceWorkStateAPI> device = (id<AIBudsDeviceWorkStateAPI>)self.device;
if (![device conformsToProtocol:@protocol(AIBudsDeviceWorkStateAPI)]) {
NSLog(@"Device does not expose a work state");
return;
}
NSLog(@"Current work state raw value: %ld", (long)device.workState);Hata Yönetimi
Completion handler veya hata sonucu yoktur. Desteklenmeyen protokol uyumluluğunu ve unknown ya da reserved enum case'lerini işleyin.
En İyi Uygulamalar
- Özelliği Doğrudan Okuyun: Bu API'yi eşzamansız durum isteği olarak modellemeyin.
- Durumu Geçici Kabul Edin: Güncel cihaz etkinliğini gösterirken değeri yeniden okuyun.
- Tüm Enum Case'lerini İşleyin: Çalışma durumları bağlantı, arama, oynatma, çekim, aktarım, yayın, OTA, kapatma ve test etkinliklerini kapsar.
Notlar
WorkStatetek bir enum değeridir; pil, şarj, takılma veya oynatma alanları içermez.- SDK bir
WorkStatussonuç modeli veyagetWorkStatusyöntemi tanımlamaz.