himbeles/motionprovider
A Combine-based CoreMotion data provider as a Swift Package.
Usage
Starting the Motion Provider
Initialize and start the MotionProvider
let motionProvider = MotionProvider()
motionProvider.start()Handling the Motion Data
Subscribe to the motionWillChange subject and store the returned Cancellable
cancellableMotion = motionProvider.motionWillChange.sink { md in
handleMotion(md)
}The function handleMotion in the sink closure is executed on every MotionData object sent by the MotionProvider.
Also, the MotionProvider is an ObservableObject which has a published property motion that updates the ObservableObject. This dynamic property can directly be accessed in SwiftUI.
Stopping the Motion Provider
Stop the MotionProvider and cancel the subscription
motionProvider.stop()
cancellableMotion?.cancel()Package Metadata
Repository: himbeles/motionprovider
Default branch: main
README: README.md