पहनने की पहचान की स्थिति देखें
पढ़ें कि पहनने की पहचान enabled है या नहीं, और इस समय कोई भी, एक या दोनों earbuds पहने गए हैं।
आवश्यकताएँ
- डिवाइस कनेक्टेड और ready है।
- डिवाइस
DeviceWearDetectionAPIके अनुरूप है।
API संदर्भ
Framework
AIBuds.xcframework
Import
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>प्रोटोकॉल
- Swift
- Objective-C
/// The protocol for device wear detection API.
protocol DeviceWearDetectionAPI: DeviceAPI {
/// Indicates whether wear detection is currently enabled
var isWearDetectionEnabled: Bool { get }
/// The current wear status of the device.
var wearStatus: WearStatus { get }
}/// The protocol for device wear detection API.
@protocol AIBudsDeviceWearDetectionAPI <AIBudsDeviceAPI>
/// Indicates whether wear detection is currently enabled
@property(nonatomic, readonly) BOOL isWearDetectionEnabled;
/// The current wear status of the device.
@property(nonatomic, readonly) enum AIBudsWearStatus wearStatus;
@endगुण
| Property | Type | विवरण |
|---|---|---|
isWearDetectionEnabled | Bool / BOOL | पहनने की पहचान इस समय enabled है या नहीं। |
wearStatus | WearStatus | बाएँ/दाएँ की मौजूदा पहनने की स्थिति। |
पहनने की स्थिति के मान
| Swift | Objective-C | अर्थ |
|---|---|---|
.unknown | AIBudsWearStatusUnknown | पहनने की स्थिति अज्ञात है। |
.notWearing | AIBudsWearStatusNotWearing | कोई भी side नहीं पहना गया है। |
.leftWearing | AIBudsWearStatusLeftWearing | केवल बायाँ side पहना गया है। |
.rightWearing | AIBudsWearStatusRightWearing | केवल दायाँ side पहना गया है। |
.bothWearing | AIBudsWearStatusBothWearing | दोनों sides पहने गए हैं। |
उपयोग के उदाहरण
- Swift
- Objective-C
import AIBuds
guard let device = device as? DeviceWearDetectionAPI else {
print("Device does not support wear detection")
return
}
print("Wear detection enabled: \(device.isWearDetectionEnabled)")
switch device.wearStatus {
case .unknown:
print("Wear state is unknown")
case .notWearing:
print("Neither side is worn")
case .leftWearing:
print("Only the left side is worn")
case .rightWearing:
print("Only the right side is worn")
case .bothWearing:
print("Both sides are worn")
@unknown default:
print("Unsupported wear-state value")
}#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
id<AIBudsDeviceWearDetectionAPI> device = (id<AIBudsDeviceWearDetectionAPI>)self.device;
if ([device conformsToProtocol:@protocol(AIBudsDeviceWearDetectionAPI)]) {
NSLog(@"Wear detection enabled: %@", device.isWearDetectionEnabled ? @"YES" : @"NO");
NSLog(@"Wear status raw value: %ld", (long)device.wearStatus);
}त्रुटि प्रबंधन
ये synchronous snapshot properties हैं और errors return नहीं करतीं। Unsupported protocol conformance और .unknown को स्पष्ट रूप से संभालें। पढ़ने के बाद वर्तमान स्थिति बदल सकती है।
श्रेष्ठ अभ्यास
- Enabled और Wear State अलग रखें:
falseऔर.notWearingअलग अवधारणाएँ हैं। - Updates देखें: UI को current रखना हो तो
didWearDetectionEnabledChangedऔरdidWearStatusChangedimplement करें। - UI Main Thread पर अपडेट करें: आवश्यकता होने पर delegate से आए UI changes को main queue पर dispatch करें।
नोट्स
- SDK
getWearDetectionSwitchStatusयाResultआधारित query methods के बजाय properties देता है। .unknownको “नहीं पहना” के रूप में न दिखाएँ।