View Wear Detection State
Read whether wear detection is enabled and whether neither, one, or both earbuds are currently worn.
Prerequisites
- The device is connected and ready.
- The device conforms to
DeviceWearDetectionAPI.
API Reference
Framework
AIBuds.xcframework
Import
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>Protocol
- 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;
@endProperties
| Property | Type | Description |
|---|---|---|
isWearDetectionEnabled | Bool / BOOL | Whether wear detection is currently enabled. |
wearStatus | WearStatus | The current left/right wear state. |
Wear Status Values
| Swift | Objective-C | Meaning |
|---|---|---|
.unknown | AIBudsWearStatusUnknown | The wear state is unknown. |
.notWearing | AIBudsWearStatusNotWearing | Neither side is worn. |
.leftWearing | AIBudsWearStatusLeftWearing | Only the left side is worn. |
.rightWearing | AIBudsWearStatusRightWearing | Only the right side is worn. |
.bothWearing | AIBudsWearStatusBothWearing | Both sides are worn. |
Usage Examples
- 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);
}Error Handling
These are synchronous snapshot properties and do not return errors. Handle unsupported protocol conformance and .unknown explicitly. A current state may change after it is read.
Best Practices
- Keep Enabled and Wear State Separate:
falseand.notWearingdescribe different concepts. - Observe Updates: Implement
didWearDetectionEnabledChangedanddidWearStatusChangedwhen the UI must remain current. - Update UI on the Main Thread: Dispatch delegate-driven UI changes to the main queue when required.
Notes
- The SDK exposes properties rather than
getWearDetectionSwitchStatusorResult-based query methods. .unknownmust not be displayed as “not wearing.”