Skip to content

Core Wear Detection Get Switch Status

Mr.P edited this page Aug 29, 2026 · 2 revisions

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

Objective-C

#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>

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

Objective-C

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

Properties

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

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

Objective-C

#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

  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.”

AIBuds SDK iOS Wiki

Clone this wiki locally