WearableDevice
public protocol WearableDevice
Represents a wearable device instance.
-
The name of the device.
Declaration
Swift
var name: String? { get } -
Provides information about the firmware version currently installed on the device.
Declaration
Swift
var firmwareVersion: FirmwareVersion? { get } -
Device information, as reported by the GATT device information service. When this value is updated, a
WearableDeviceEvent.didUpdateDeviceInformation(DeviceInformation)event is fired.Declaration
Swift
var deviceInformation: DeviceInformation? { get } -
Refreshes the device information. When the new value is received, the
deviceInformationproperty is updated.Declaration
Swift
func refreshDeviceInformation() -
Wearable device information. When this value is updated, a
WearableDeviceEvent.didUpdateWearableDeviceInformation(WearableDeviceInformation)event is fired.Declaration
Swift
var wearableDeviceInformation: WearableDeviceInformation? { get } -
Refreshes the wearable device information. When the new value is received, the
wearableDeviceInformationproperty is updated.Declaration
Swift
func refreshWearableDeviceInformation() -
Information about the sensors provided by the wearable device. When this value is updated, a
WearableDeviceEvent.didUpdateSensorInformation(SensorInformation)event is fired.Declaration
Swift
var sensorInformation: SensorInformation? { get } -
Refreshes the sensor information. When the new value is received, the
sensorInformationproperty is updated.Declaration
Swift
func refreshSensorInformation() -
The configuration of the sensors provided by the wearable device. When this value is updated, a
WearableDeviceEvent.didUpdateSensorConfiguration(SensorConfiguration)event is fired.Declaration
Swift
var sensorConfiguration: SensorConfiguration? { get } -
Refreshes the sensor configuration. When a new value is received, the
sensorConfigurationproperty is updated.Declaration
Swift
func refreshSensorConfiguration() -
Requests a change to the current sensor configuration. When this function is called, the specified sensor configuration value is written to the remote device. If the remote device accepts the new configuration, the
sensorConfigurationproperty is updated. If the remote device rejects the new configuration, aWearableDeviceEvent.didFailToWriteSensorConfiguration(Error)event is fired.Declaration
Swift
func changeSensorConfiguration(_ newConfiguration: SensorConfiguration) -
Information about the gestures provided by the wearable device. When this value is updated, a
WearableDeviceEvent.didUpdateGestureInformation(GestureInformation)event is fired.Declaration
Swift
var gestureInformation: GestureInformation? { get } -
Refreshes the gesture information. When a new value is received, the
gestureInformationproperty is updated.Declaration
Swift
func refreshGestureInformation() -
The configuration of the gesture recognition facility provided by the wearable device. When this value is updated, a
WearableDeviceEvent.didUpdateGestureConfiguration(GestureConfiguration)event is fired.Declaration
Swift
var gestureConfiguration: GestureConfiguration? { get } -
Refreshes the gesture configuration. When a new value is received, the
gestureConfigurationproperty is updated.Declaration
Swift
func refreshGestureConfiguration() -
Requests a change to the current gesture configuration. When this function is called, the specified gesture configuration value is written to the remote device. If the remote device accepts the new configuration, the
gestureConfigurationproperty is updated. If the remote device rejects the new configuration, aWearableDeviceEvent.didFailToWriteGestureConfiguration(Error)event is fired.Declaration
Swift
func changeGestureConfiguration(_ newConfiguration: GestureConfiguration) -
Indicates whether the wearable sensor service is suspended. On certain devices, certain user-initiated activities cause the wearable sensor service to be suspended due to bandwidth or processing restrictions.
Declaration
Swift
var isWearableSensorServiceSuspended: Bool { get } -
Check if the device satisfies the intended sensor and gesture usage.
Declaration
Swift
func validateIntents(sensor sensorIntent: SensorIntent, gesture gestureIntent: GestureIntent) -> Result<Void> -
Retrieves the current controllable noise cancellation settings from the device. The provided completion handler will be invoked with either the current controllable noise cancellation settings or an error indicating a failure.
Declaration
Swift
func getControllableNoiseCancellation(completionHandler: @escaping (Result<ControllableNoiseCancellation>) -> Void) -
Sets the controllable noise cancellation level. The provided completion handler will be invoked with either the new controllable noise cancellation settings or an error indicating a failure.
Controllable Noise Cancellation is a feature which allows the user to control the amount of noise cancelling within the product. Lower CNC steps apply more Noise Cancellation in the product (i.e. less noise) and higher CNC steps apply less Noise Cancellation (i.e. more noise) in the product.
Declaration
Swift
func setControllableNoiseCancellation(level: UInt8, isEnabled: Bool, completionHandler: @escaping (Result<ControllableNoiseCancellation>) -> Void)Parameters
levelA value from 0 to
numberOfSteps - 1in the currentControllableNoiseCancellationsetting on the device.isEnabledIndicates whether noise cancellation should be enabled.
completionHandlerInvoked with either the new controllable noise cancellation settings or an error indicating a failure.
-
Retrieves the current active noise reduction settings from the device. The provided completion handler will be invoked with either the current active noise reduction settings or an error indicating a failure.
Declaration
Swift
func getActiveNoiseReduction(completionHandler: @escaping (Result<ActiveNoiseReduction>) -> Void) -
Sets the active noise reduction mode. The provided completion handler will be invoked with either the new active noise reduction settings or an error indicating a failure.
Declaration
Swift
func setActiveNoiseReduction(mode: ActiveNoiseReduction.Mode, completionHandler: @escaping (Result<ActiveNoiseReduction>) -> Void) -
Sets the name of the product. The provided completion handler will be invoked with either the new name or an error indicating the failure
Declaration
Swift
func setProductName(name: String, completionHandler: @escaping ((Result<(String, Bool)>) -> Void)) -
Gets the name of the product. The provided completion handler will be invoked with either the name or an error indicating the failure
Declaration
Swift
func getProductName(completionHandler: @escaping ((Result<(String, Bool)>) -> Void)) -
Gets the batteyr level of the product. The provided completion handler will be invoked with either the battery level or an error indicating the failure
Declaration
Swift
func getBatteryLevel(completionHandler: @escaping ((Result<UInt8>) -> Void))
-
WearableDeviceEventHandlerExtension methodCallback type that receives a
WearableDeviceEvent.Declaration
Swift
public typealias WearableDeviceEventHandler = (WearableDeviceEvent) -> Void -
addEventListener(queue:handler:)Extension methodRegisters a handler block to be executed on the specified queue whenever a
WearableDeviceEventis posted from thisWearableDeviceobject.Note that the returned
ListenerTokenmust be retained. Once it is deallocated, the listener is deregistered.If the closure passed to this function references
self, you must add[weak self]to the closure’s capture list. Failing to do so will result in a retain cycle and leaked memory.Declaration
Swift
public func addEventListener(queue: OperationQueue?, handler: @escaping WearableDeviceEventHandler) -> ListenerTokenParameters
queueThe queue on which to execute the block. If you pass
nil, the block is run synchronously on the posting thread.handlerThe block to be executed when the event is received.
Return Value
An opaque
ListenerTokenobject. The listener is automatically deregistered when this token object is deallocated, so be sure to retain a reference to it.
-
configureSensors(_:)Extension methodConfigure the sensors on a wearable device. The caller provides a block to this function that takes a
SensorConfigurationvalue. The currentSensorConfigurationis passed to the block which is executed synchronously on the calling thread. ThatSensorConfigurationvalue can be modified to match the desired configuration. Once the block returns, that updated configuration is then sent to the wearable device (viaWearableDevice.changeSensorConfiguration(_:)).If the remote device accepts the new configuration, a
WearableDeviceEvent.didWriteSensorConfigurationevent is fired. Then thesensorConfigurationproperty is updated to the new value, which causes aWearableDeviceEvent.didUpdateSensorConfiguration(SensorConfiguration)event to be fired. If the remote device rejects the new configuration, aWearableDeviceEvent.didFailToWriteSensorConfiguration(Error)event is fired.For example, to enable the accelerometer and gyroscope at 50 Hz (20 ms update period):
device.configureSensors { config in // Reset the configuration so all other sensors are disabled. config.disableAll() // Enable the desired sensors. config.enable(.accelerometer, at: ._20ms) config.enable(.gyroscope, at: ._20ms) }Declaration
Swift
public func configureSensors(_ body: (inout SensorConfiguration) -> Void) -
configureGestures(_:)Extension methodConfigure the gestures on a wearable device. The caller provides a block to this function that takes a
GestureConfigurationvalue. The currentGestureConfigurationis passed to the block which is executed synchronously on the calling thread. ThatGestureConfigurationvalue can be modified to match the desired configuration. Once the block returns, that updated configuration is then sent to the wearable device (viaWearableDevice.changeGestureConfiguration(_:)).If the remote device accepts the new configuration, a
WearableDeviceEvent.didWriteGestureConfigurationevent is fired. Then thegestureConfigurationproperty is updated to the new value, which causes aWearableDeviceEvent.didUpdateGestureConfiguration(GestureConfiguration)event to be fired. If the remote device rejects the new configuration, aWearableDeviceEvent.didFailToWriteGestureConfiguration(Error)event is fired.For example, to enable the double-tap gesture:
device.configureGestures { config in // Reset the configuration so all other gestures are disabled. config.disableAll() // Enable the desired gestures. config.set(gesture: .doubleTap, enabled: true) }Declaration
Swift
public func configureGestures(_ body: (inout GestureConfiguration) -> Void)
WearableDevice Protocol Reference