1

It's seems no way to get realtime Accelerometer data on WatchOS after wrist down ,screen is off. get data from CMMotionManager will stop after seconds for Apple's battery care.

You can query data from HKWorkoutSession in background ,for example: step count、calories、heart beats rate ,but it cannot query Accelerometer data or CMDeviceMotion data.

I google it a lot and I test with this code.
https://developer.apple.com/videos/play/wwdc2016/713/

WWDC sample code download

It's not accurate because of screen off problem. It will not print CMDeviceMotion data in XCode when your screen off .

Someone says MSensorRecorder maybe work, but it has 3 sec delay.

Is there a way to get this?

Haozes
  • 352
  • 2
  • 12

1 Answers1

2

When screen is off, your app is being suspended. So, your the problem is not "CMMotionManager does not give data when screen is off", but "my app is not running when screen is off".

As a workaround, you can start workout: while workout is active, your app will be running in background and you can continue requesting data from CMMotionManager same way as you are doing it now. But be careful: app can not use more than 15% of CPU while running in background workout, else it will be killed by watchdog.

Watch this WWDC videos for more details on workout and background modes: Building Great Workout Apps, Keeping Your Watch App Up to Date, Architecting for Performance on watchOS 3

abjurato
  • 1,439
  • 11
  • 17