मुख्य कंटेंट तक स्किप करें

पहनने की पहचान की क्षमता देखें

पढ़ें कि डिवाइस पहनने की पहचान का समर्थन करता है या नहीं, और इस सुविधा को configure किया जा सकता है या नहीं।

आवश्यकताएँ

  • डिवाइस कनेक्टेड और ready है।
  • डिवाइस DeviceWearDetectionAPI के अनुरूप है।

API संदर्भ

Framework

AIBuds.xcframework

Import

Swift
import AIBuds

प्रोटोकॉल

यह capability DeviceWearDetectionAPI की property है।

Swift
/// The protocol for device wear detection API.
protocol DeviceWearDetectionAPI: DeviceAPI {
    /// The wear-detection capabilities supported by the device
    var wearDetectionCapability: WearDetectionCapability { get }
}

गुण

PropertyTypeविवरण
wearDetectionCapabilityWearDetectionCapabilityडिवाइस द्वारा बताई गई मौजूदा capability।

समर्थित मान

SwiftObjective-Cअर्थ
.noneAIBudsWearDetectionCapabilityNoneसमर्थित नहीं।
.supportedNotConfigurableAIBudsWearDetectionCapabilitySupportedNotConfigurableसमर्थित है, लेकिन configurable नहीं।
.supportedAndConfigurableAIBudsWearDetectionCapabilitySupportedAndConfigurableसमर्थित और configurable है।

उपयोग के उदाहरण

Swift
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")
}

त्रुटि प्रबंधन

इस property का completion handler नहीं है। Protocol conformance विफल होने और भविष्य के अज्ञात enum values को संभालें। .none को transport error न मानें; यह valid capability value है।

श्रेष्ठ अभ्यास

  1. Configure करने से पहले पढ़ें: Enable/disable control दिखाने से पहले capability जाँचें।
  2. सभी Capability Levels अलग रखें: “configurable नहीं” को “समर्थित नहीं” में न मिलाएँ।
  3. भविष्य के मान संभालें: Swift में enum पर switch करते समय @unknown default उपयोग करें।

नोट्स

  • यह synchronous property read है, asynchronous getWearDetectionSupport method नहीं।
  • SDK Demo इसी property से तय करता है कि configuration controls उपलब्ध हों या नहीं।