ComposableCoreMotion Documentation

Structure Headphone​Motion​Manager

@available(iOS 14, *)
  @available(macCatalyst 14, *)
  @available(macOS, unavailable)
  @available(tvOS, unavailable)
  @available(watchOS 7, *)
  public struct HeadphoneMotionManager  

A wrapper around Core Motion's CMHeadphoneMotionManager that exposes its functionality through effects and actions, making it easy to use with the Composable Architecture, and easy to test.

Nested Types

HeadphoneMotionManager.Action

Actions that correspond to CMHeadphoneMotionManagerDelegate methods.

Initializers

init(create:​destroy:​device​Motion:​is​Device​Motion​Active:​is​Device​Motion​Available:​start​Device​Motion​Updates:​stop​Device​Motion​Updates:​)

public init(
      create: @escaping (AnyHashable) -> Effect<Action, Never>,
      destroy: @escaping (AnyHashable) -> Effect<Never, Never>,
      deviceMotion: @escaping (AnyHashable) -> DeviceMotion?,
      isDeviceMotionActive: @escaping (AnyHashable) -> Bool,
      isDeviceMotionAvailable: @escaping (AnyHashable) -> Bool,
      startDeviceMotionUpdates: @escaping (AnyHashable, OperationQueue) ->
        Effect<DeviceMotion, Error>,
      stopDeviceMotionUpdates: @escaping (AnyHashable) -> Effect<Never, Never>
    )  

Properties

live

public static let live  

Methods

create(id:​)

public func create(id: AnyHashable) -> Effect<Action, Never>  

Creates a headphone motion manager.

A motion manager must be first created before you can use its functionality, such as starting device motion updates or accessing data directly from the manager.

destroy(id:​)

public func destroy(id: AnyHashable) -> Effect<Never, Never>  

Destroys a currently running headphone motion manager.

In is good practice to destroy a headphone motion manager once you are done with it, such as when you leave a screen or no longer need motion data.

device​Motion(id:​)

public func deviceMotion(id: AnyHashable) -> DeviceMotion?  

The latest sample of device-motion data.

is​Device​Motion​Active(id:​)

public func isDeviceMotionActive(id: AnyHashable) -> Bool  

A Boolean value that determines whether the app is receiving updates from the device-motion service.

is​Device​Motion​Available(id:​)

public func isDeviceMotionAvailable(id: AnyHashable) -> Bool  

A Boolean value that indicates whether the device-motion service is available on the device.

start​Device​Motion​Updates(id:​to:​)

public func startDeviceMotionUpdates(
      id: AnyHashable,
      to queue: OperationQueue = .main
    ) -> Effect<DeviceMotion, Error>  

Starts device-motion updates without a block handler.

Returns a long-living effect that emits device motion data each time the headphone motion manager receives a new value.

stop​Device​Motion​Updates(id:​)

public func stopDeviceMotionUpdates(id: AnyHashable) -> Effect<Never, Never>  

Stops device-motion updates.

unimplemented(create:​destroy:​device​Motion:​is​Device​Motion​Active:​is​Device​Motion​Available:​start​Device​Motion​Updates:​stop​Device​Motion​Updates:​)

public static func unimplemented(
      create: @escaping (AnyHashable) -> Effect<Action, Never> = { _ in _unimplemented("create") },
      destroy: @escaping (AnyHashable) -> Effect<Never, Never> = { _ in _unimplemented("destroy") },
      deviceMotion: @escaping (AnyHashable) -> DeviceMotion? = { _ in _unimplemented("deviceMotion")
      },
      isDeviceMotionActive: @escaping (AnyHashable) -> Bool = { _ in
        _unimplemented("isDeviceMotionActive")
      },
      isDeviceMotionAvailable: @escaping (AnyHashable) -> Bool = { _ in
        _unimplemented("isDeviceMotionAvailable")
      },
      startDeviceMotionUpdates: @escaping (AnyHashable, OperationQueue) ->
        Effect<DeviceMotion, Error> = { _, _ in _unimplemented("startDeviceMotionUpdates") },
      stopDeviceMotionUpdates: @escaping (AnyHashable) -> Effect<Never, Never> = { _ in
        _unimplemented("stopDeviceMotionUpdates")
      }
    ) -> HeadphoneMotionManager