Structure
HeadphoneMotionManager
@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.
Relationships
Nested Types
HeadphoneMotionManager.Action
Actions that correspond to
CMHeadphoneMotionManagerDelegate
methods.
Initializers
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.
deviceMotion(id:)
public func deviceMotion(id: AnyHashable) -> DeviceMotion?
The latest sample of device-motion data.
isDeviceMotionActive(id:)
public func isDeviceMotionActive(id: AnyHashable) -> Bool
A Boolean value that determines whether the app is receiving updates from the device-motion service.
startDeviceMotionUpdates(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.
stopDeviceMotionUpdates(id:)
public func stopDeviceMotionUpdates(id: AnyHashable) -> Effect<Never, Never>
Stops device-motion updates.