I'm working on an independent application for WatchOS (without the iOS companion app) where I aim to utilise the accelerometer data from my AirPods Pro. I'm using CMHeadphoneMotionManager for this purpose. However, I'm encountering an issue where I don't receive any updates and the isDeviceMotionAvailable property returns false. This issue only occurs when I run my code WatchOS; it operates as expected on iOS demo app.
Here's a snippet of my code:
let motionManager = CMHeadphoneMotionManager()
func startMotionUpdates() {
if motionManager.isDeviceMotionAvailable {
motionManager.startDeviceMotionUpdates(to: .main) { (motion, error) in
// Process motion data
}
} else {
print("Device motion updates are not available.")
}
}
I expected to receive motion updates in the WatchOS app similar to the iOS app, but the isDeviceMotionAvailable is always false, and the updates are not being received. I found a similar query on the Apple forum, so someone else also has this problem. Does anyone know why this happens and how I can fix it?