Возможности распознавания ношения
Проверьте, поддерживает ли устройство распознавание ношения и можно ли его настраивать.
Предварительные условия
- Устройство подключено и готово к работе.
- Устройство поддерживает
DeviceWearDetectionAPI.
Справочник API
Фреймворк
AIBuds.xcframework
Импорт
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>Протокол
Возможность предоставляется свойством DeviceWearDetectionAPI.
- Swift
- Objective-C
/// The protocol for device wear detection API.
protocol DeviceWearDetectionAPI: DeviceAPI {
/// The wear-detection capabilities supported by the device
var wearDetectionCapability: WearDetectionCapability { get }
}/// The protocol for device wear detection API.
@protocol AIBudsDeviceWearDetectionAPI <AIBudsDeviceAPI>
/// The wear-detection capabilities supported by the device
@property(nonatomic, readonly) enum AIBudsWearDetectionCapability wearDetectionCapability;
@endСвойства
| Свойство | Тип | Описание |
|---|---|---|
wearDetectionCapability | WearDetectionCapability | Возможность, которую сейчас сообщает устройство. |
Поддерживаемые значения
| Swift | Objective-C | Смысл |
|---|---|---|
.none | AIBudsWearDetectionCapabilityNone | Не поддерживается. |
.supportedNotConfigurable | AIBudsWearDetectionCapabilitySupportedNotConfigurable | Поддерживается, но не настраивается. |
.supportedAndConfigurable | AIBudsWearDetectionCapabilitySupportedAndConfigurable | Поддерживается и настраивается. |
Примеры использования
- Swift
- Objective-C
import AIBuds
guard let device = device as? DeviceWearDetectionAPI else {
print("Wear detection is not exposed by this device")
return
}
switch device.wearDetectionCapability {
case .none:
print("Wear detection is not supported")
case .supportedNotConfigurable:
print("Wear detection is supported but not configurable")
case .supportedAndConfigurable:
print("Wear detection is supported and configurable")
@unknown default:
print("Unknown wear-detection capability")
}#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
id<AIBudsDeviceWearDetectionAPI> device = (id<AIBudsDeviceWearDetectionAPI>)self.device;
if (![device conformsToProtocol:@protocol(AIBudsDeviceWearDetectionAPI)]) {
NSLog(@"Wear detection is not exposed by this device");
return;
}
switch (device.wearDetectionCapability) {
case AIBudsWearDetectionCapabilityNone:
NSLog(@"Wear detection is not supported");
break;
case AIBudsWearDetectionCapabilitySupportedNotConfigurable:
NSLog(@"Wear detection is supported but not configurable");
break;
case AIBudsWearDetectionCapabilitySupportedAndConfigurable:
NSLog(@"Wear detection is supported and configurable");
break;
}Обработка ошибок
У свойства нет обработчика завершения. Обрабатывайте неподдерживаемый протокол и будущие неизвестные варианты перечисления. Не считайте .none транспортной ошибкой: это допустимое значение возможности.
Рекомендации
- Читайте до настройки: проверьте возможность до отображения переключателя.
- Сохраняйте все уровни: не объединяйте «не настраивается» с «не поддерживается».
- Обрабатывайте будущие значения: используйте
@unknown defaultв Swift при разборе перечисления.
Примечания
- Это синхронное чтение свойства, а не асинхронный метод
getWearDetectionSupport. - Demo SDK по этому свойству определяет, нужно ли показывать элементы настройки.