पहनने की पहचान सेट करें
जब डिवाइस configurable capability बताए, तब पहनने की पहचान enable या disable करें।
आवश्यकताएँ
- डिवाइस कनेक्टेड और ready है।
- डिवाइस
DeviceWearDetectionAPIके अनुरूप है। wearDetectionCapabilityका मान.supportedAndConfigurableहै।
API संदर्भ
Framework
AIBuds.xcframework
Import
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>प्रोटोकॉल
यह method DeviceWearDetectionAPI में परिभाषित है।
- Swift
- Objective-C
/// 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?
)
}/// The protocol for device wear detection API.
@protocol AIBudsDeviceWearDetectionAPI <AIBudsDeviceAPI>
/// 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.
- (void)setWearDetectionEnabled:(BOOL)enabled
completion:(AIBudsCompletionHandler _Nullable)completion;
@endInstance विधि
पहनने की पहचान enable या disable करता है।
API संदर्भ मेंsetWearDetection खोलें।
- Swift
- Objective-C
/// 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?
)/// 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.
- (void)setWearDetectionEnabled:(BOOL)enabled
completion:(AIBudsCompletionHandler _Nullable)completion;पैरामीटर
| Parameter | Type | विवरण |
|---|---|---|
enabled | Bool / BOOL | पहनने की पहचान enable करने के लिए true/YES; अन्यथा disable करें। |
completion | AIBudsCompletionHandler? | Operation समाप्त होने पर चलने वाला optional completion handler। |
Callback पैरामीटर:
| नाम | Type | विवरण |
|---|---|---|
success | Bool / BOOL | Operation सफल हुआ या नहीं। |
error | NSError? | विफलता का विवरण; सफलता पर nil। |
Return मान
यह method सीधे कोई मान return नहीं करता।
उपयोग के उदाहरण
- Swift
- Objective-C
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")
}#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
id<AIBudsDeviceWearDetectionAPI> device = (id<AIBudsDeviceWearDetectionAPI>)self.device;
if (![device conformsToProtocol:@protocol(AIBudsDeviceWearDetectionAPI)]) {
return;
}
if (device.wearDetectionCapability != AIBudsWearDetectionCapabilitySupportedAndConfigurable) {
NSLog(@"Wear detection is not configurable");
return;
}
[device
setWearDetectionEnabled:YES
completion:^(BOOL success, NSError *_Nullable error) {
if (!success) {
NSLog(@"Failed to enable wear detection: %@", error.localizedDescription);
return;
}
NSLog(@"Wear detection enabled");
}];त्रुटि प्रबंधन
Local UI अपडेट करने से पहले success जाँचें और विफलता के विवरण के लिए error उपयोग करें। Capability .none या .supportedNotConfigurable हो तो method न बुलाएँ।
श्रेष्ठ अभ्यास
- Capability Validate करें: Command भेजने से पहले
.supportedAndConfigurableआवश्यक मानें। - अनावश्यक Commands से बचें: पहले requested value की
isWearDetectionEnabledसे तुलना करें। - सफलता के बाद Refresh करें: लागू स्थिति दिखाने से पहले current property पढ़ें या
didWearDetectionEnabledChangedकी प्रतीक्षा करें।
नोट्स
- SDK Demo पहनने की पहचान enable या disable करने से पहले यही capability check करता है।
- यह method automatic music pause या resume behavior परिभाषित नहीं करता।