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 deviceInformation property 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 wearableDeviceInformation property 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 sensorInformation property 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 sensorConfiguration property 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 sensorConfiguration property is updated. If the remote device rejects the new configuration, a WearableDeviceEvent.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 gestureInformation property 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 gestureConfiguration property 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 gestureConfiguration property is updated. If the remote device rejects the new configuration, a WearableDeviceEvent.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

    level

    A value from 0 to numberOfSteps - 1 in the current ControllableNoiseCancellation setting on the device.

    isEnabled

    Indicates whether noise cancellation should be enabled.

    completionHandler

    Invoked 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))
  • WearableDeviceEventHandler Extension method

    Callback type that receives a WearableDeviceEvent.

    Declaration

    Swift

    public typealias WearableDeviceEventHandler = (WearableDeviceEvent) -> Void
  • Registers a handler block to be executed on the specified queue whenever a WearableDeviceEvent is posted from this WearableDevice object.

    Note that the returned ListenerToken must 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) -> ListenerToken

    Parameters

    queue

    The queue on which to execute the block. If you pass nil, the block is run synchronously on the posting thread.

    handler

    The block to be executed when the event is received.

    Return Value

    An opaque ListenerToken object. The listener is automatically deregistered when this token object is deallocated, so be sure to retain a reference to it.

  • configureSensors(_:) Extension method

    Configure the sensors on a wearable device. The caller provides a block to this function that takes a SensorConfiguration value. The current SensorConfiguration is passed to the block which is executed synchronously on the calling thread. That SensorConfiguration value can be modified to match the desired configuration. Once the block returns, that updated configuration is then sent to the wearable device (via WearableDevice.changeSensorConfiguration(_:)).

    If the remote device accepts the new configuration, a WearableDeviceEvent.didWriteSensorConfiguration event is fired. Then the sensorConfiguration property is updated to the new value, which causes a WearableDeviceEvent.didUpdateSensorConfiguration(SensorConfiguration) event to be fired. If the remote device rejects the new configuration, a WearableDeviceEvent.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 method

    Configure the gestures on a wearable device. The caller provides a block to this function that takes a GestureConfiguration value. The current GestureConfiguration is passed to the block which is executed synchronously on the calling thread. That GestureConfiguration value can be modified to match the desired configuration. Once the block returns, that updated configuration is then sent to the wearable device (via WearableDevice.changeGestureConfiguration(_:)).

    If the remote device accepts the new configuration, a WearableDeviceEvent.didWriteGestureConfiguration event is fired. Then the gestureConfiguration property is updated to the new value, which causes a WearableDeviceEvent.didUpdateGestureConfiguration(GestureConfiguration) event to be fired. If the remote device rejects the new configuration, a WearableDeviceEvent.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)