Ana içeriğe geç

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 DeviceWearDetectionAPI protokolüne uyar.
  • wearDetectionCapability, .supportedAndConfigurable değerindedir.

API Referansı

Framework

AIBuds.xcframework

İçe Aktarma

Swift
import AIBuds

Protokol

Yöntem DeviceWearDetectionAPI tarafından tanımlanır.

Swift
/// 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?
    )
}

Örnek Yöntemi

Takma algılamayı etkinleştirir veya devre dışı bırakır.

API Referansında setWearDetection öğesini açın.
Swift
/// 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?
)

Parametreler

ParametreTürAçıklama
enabledBool / BOOLTakma algılamayı etkinleştirmek için true/YES; devre dışı bırakmak için aksi değer.
completionAIBudsCompletionHandler?İşlem tamamlandığında çağrılan isteğe bağlı completion handler.

Callback Parametreleri:

AdTürAçıklama
successBool / BOOLİşlemin başarılı olup olmadığı.
errorNSError?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
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")
}

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

  1. Yeteneği Doğrulayın: Komutu göndermeden önce .supportedAndConfigurable değerini şart koşun.
  2. Gereksiz Komutlardan Kaçının: Önce istenen değeri isWearDetectionEnabled ile karşılaştırın.
  3. Başarıdan Sonra Yenileyin: Uygulanan durumu göstermeden önce güncel özelliği okuyun veya didWearDetectionEnabledChanged olayı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.