Overview
RadarMotionProtocol defines the interface for motion activity detection providers that can be integrated with the Radar SDK. This protocol enables the SDK to receive motion activity updates, relative altitude updates, and absolute altitude updates from CoreMotion or custom motion providers.
Implementing this protocol allows for custom motion detection backends or wrapping of Apple’s CoreMotion framework.
Required Methods
startActivityUpdatesToQueue(_:withHandler:)
Starts monitoring motion activity updates and delivers them to a specified queue.The operation queue on which to deliver motion activity updates.
The block to invoke with motion activity updates. The handler receives
CMMotionActivity objects representing the user’s current activity state.CMMotionActivityHandler is a block type defined as void (^)(CMMotionActivity *activity).stopActivityUpdates
Stops monitoring motion activity updates.startRelativeAltitudeUpdatesToQueue(_:withHandler:)
Starts monitoring relative altitude changes and delivers them to a specified queue.The operation queue on which to deliver altitude updates.
The block to invoke with relative altitude updates. The handler receives
CMAltitudeData objects representing altitude changes relative to a starting point.Relative altitude measures changes from when monitoring started, useful for detecting floor changes in buildings.
stopRelativeAltitudeUpdates
Stops monitoring relative altitude updates.startAbsoluteAltitudeUpdatesToQueue(_:withHandler:)
Starts monitoring absolute altitude and delivers updates to a specified queue.The operation queue on which to deliver altitude updates.
The block to invoke with absolute altitude updates. The handler receives
CMAltitudeData objects representing altitude above sea level.Absolute altitude provides elevation above sea level when available from device sensors.
stopAbsoluteAltitudeUpdates
Stops monitoring absolute altitude updates.stringForMotionAuthorization
Returns a string representation of the current motion authorization status.Implementation Example
Here’s an example implementation using CoreMotion:Usage Notes
- Battery Impact: Motion and altitude updates can significantly impact battery life. Stop updates when not needed.
- Authorization: Check
CMMotionActivityManager.authorizationStatus()before starting updates. - Queue Management: Use an appropriate operation queue for your app’s threading model. For UI updates, use
OperationQueue.main. - Data Quality: Altitude data accuracy depends on device sensors and environmental conditions.
Related APIs
- Apple’s CMMotionActivityManager
- Apple’s CMAltimeter
- Apple’s CMMotionActivity
See Also
- RadarIndoorsProtocol - Protocol for indoor positioning providers