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

पहनने की पहचान सेट करें

जब डिवाइस configurable capability बताए, तब पहनने की पहचान enable या disable करें।

आवश्यकताएँ

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

API संदर्भ

Framework

AIBuds.xcframework

Import

Swift
import AIBuds

प्रोटोकॉल

यह method DeviceWearDetectionAPI में परिभाषित है।

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

Instance विधि

पहनने की पहचान enable या disable करता है।

API संदर्भ में setWearDetection खोलें।
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?
)

पैरामीटर

ParameterTypeविवरण
enabledBool / BOOLपहनने की पहचान enable करने के लिए true/YES; अन्यथा disable करें।
completionAIBudsCompletionHandler?Operation समाप्त होने पर चलने वाला optional completion handler।

Callback पैरामीटर:

नामTypeविवरण
successBool / BOOLOperation सफल हुआ या नहीं।
errorNSError?विफलता का विवरण; सफलता पर nil

Return मान

यह method सीधे कोई मान return नहीं करता।

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

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

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

Local UI अपडेट करने से पहले success जाँचें और विफलता के विवरण के लिए error उपयोग करें। Capability .none या .supportedNotConfigurable हो तो method न बुलाएँ।

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

  1. Capability Validate करें: Command भेजने से पहले .supportedAndConfigurable आवश्यक मानें।
  2. अनावश्यक Commands से बचें: पहले requested value की isWearDetectionEnabled से तुलना करें।
  3. सफलता के बाद Refresh करें: लागू स्थिति दिखाने से पहले current property पढ़ें या didWearDetectionEnabledChanged की प्रतीक्षा करें।

नोट्स

  • SDK Demo पहनने की पहचान enable या disable करने से पहले यही capability check करता है।
  • यह method automatic music pause या resume behavior परिभाषित नहीं करता।