착용 감지 상태 확인
착용 감지 활성화 여부와 이어버드의 미착용, 한쪽 착용 또는 양쪽 착용 상태를 읽습니다.
사전 요구 사항
- 기기가 연결되어 사용할 수 있는 상태입니다.
- 기기가
DeviceWearDetectionAPI를 준수합니다.
API 참고
프레임워크
AIBuds.xcframework
가져오기
- 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속성
| 속성 | 타입 | 설명 |
|---|---|---|
isWearDetectionEnabled | Bool / BOOL | 착용 감지의 현재 활성화 여부입니다. |
wearStatus | WearStatus | 현재 좌우 착용 상태입니다. |
착용 상태 값
| Swift | Objective-C | 의미 |
|---|---|---|
.unknown | AIBudsWearStatusUnknown | 착용 상태를 알 수 없습니다. |
.notWearing | AIBudsWearStatusNotWearing | 양쪽 모두 착용하지 않았습니다. |
.leftWearing | AIBudsWearStatusLeftWearing | 왼쪽만 착용했습니다. |
.rightWearing | AIBudsWearStatusRightWearing | 오른쪽만 착용했습니다. |
.bothWearing | AIBudsWearStatusBothWearing | 양쪽 모두 착용했습니다. |
사용 예제
- 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);
}오류 처리
이 값은 동기식 스냅샷 속성이며 오류를 반환하지 않습니다. 프로토콜 미지원과 .unknown을 명시적으로 처리하세요. 현재 상태는 값을 읽은 뒤 변경될 수 있습니다.
권장 사항
- 활성화와 착용 상태 구분:
false와.notWearing은 서로 다른 상태를 나타냅니다. - 변경 관찰: UI에 최신 상태를 유지하려면
didWearDetectionEnabledChanged와didWearStatusChanged를 구현하세요. - 메인 스레드에서 UI 변경: delegate에서 수행하는 UI 변경은 필요할 때 메인 큐로 전달하세요.
참고
- SDK는
getWearDetectionSwitchStatus또는Result기반 조회 메서드 대신 속성을 제공합니다. .unknown을 ‘미착용’으로 표시하면 안 됩니다.