SensorDispatch

public class SensorDispatch

A SensorDispatch object is used to receive sensor readings. A SensorDispatch object listens for the underlying WearableDeviceEvent notifications indicating that sensor data has been received. It then unpacks the individual values from the data and dispatches each to its appropriate callback block and to its handler (a SensorDispatchHandler object).

An app can have arbitrarily many SensorDispatch objects. This allows multiple handlers inside an app all to listen to the same sensor. Each SensorDispatch automatically registers and deregisters for the appropriate WearableDeviceEvent notifications.

A SensorDispatch object is created with an associated OperationQueue. Specifying the .main queue is suitable for when the app’s user interface should be updated in response to the event. Otherwise, a background OperationQueue can be provided.

When a WearableDeviceEvent.didReceiveSensorData(SensorData) notification is received, the SensorDispatch object does the following on the OperationQueue provided to the SensorDispatch initializer:

Callbacks are only invoked if they are non-nil. Thus you need only provide callback blocks for sensors you are interested in. Similarly, the SensorDispatchHandler protocol provides default implementation of all of its handler functions. Thus you need only provide implementations for sensors you are interested in. A SensorDispatchHandler and callback blocks can co-exist. Each callback is invoked before the corresponding SensorDispatchHandler function.

  • The sensor dispatch handler. This is invoked in response to any incoming sensor data.

    Declaration

    Swift

    public weak var handler: SensorDispatchHandler?
  • Creates a new SensorDispatch object that will dispatch incoming sensor data on the specified operation queue.

    Declaration

    Swift

    public init(queue: OperationQueue, session: WearableDeviceSession? = nil)
  • Callback to receive aggregated sensor data. This is useful if you need to tie together the various readings received in a single update.

    Declaration

    Swift

    public var sensorDataCallback: ((SensorData) -> Void)?