Skip to main content

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
import AIBuds

Protocol​

Swift
/// 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 }
}

Properties​

PropertyTypeDescription
isWearDetectionEnabledBool / BOOLWhether wear detection is currently enabled.
wearStatusWearStatusThe current left/right wear state.

Wear Status Values​

SwiftObjective-CMeaning
.unknownAIBudsWearStatusUnknownThe wear state is unknown.
.notWearingAIBudsWearStatusNotWearingNeither side is worn.
.leftWearingAIBudsWearStatusLeftWearingOnly the left side is worn.
.rightWearingAIBudsWearStatusRightWearingOnly the right side is worn.
.bothWearingAIBudsWearStatusBothWearingBoth sides are worn.

Usage Examples​

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

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​

  1. Keep Enabled and Wear State Separate: false and .notWearing describe different concepts.
  2. Observe Updates: Implement didWearDetectionEnabledChanged and didWearStatusChanged when the UI must remain current.
  3. Update UI on the Main Thread: Dispatch delegate-driven UI changes to the main queue when required.

Notes​

  • The SDK exposes properties rather than getWearDetectionSwitchStatus or Result-based query methods.
  • .unknown must not be displayed as “not wearing.”