watchOS 10 CMBatchedSensorManager, crashes on startDeviceMotionUpdates / startAccelerometerUpdates
Asked Answered
J

2

0

I've been waiting to try these APIs. I had already tried them on Beta with no luck and thought on release I would be able to use them. Today I tried with xCode 15 and any calls to start something from the CMBatchedSensorManager will result in a crash after a few seconds on the thread:

Thread 7 Queue : com.apple.tcc.kTCCServiceMotion (serial)

No error message, just crash.

Am I doing something wrong?

Update:

I had read somewhere that HealthKit is required but then forgotten about it. However, I tried now with adding capabilities to both my iOS and watchOS project. I still don't get it working.

I call HKHealthStore.isHealthDataAvailable() and can see it's available on both my devices. I create let healthStore = HKHealthStore() in my App class even though I don't use it. Then when I call

private let batchedMotion = CMBatchedSensorManager()

func startBatchUpdate() {
    print("starting")
    batchedMotion.startDeviceMotionUpdates { (x, e) in
        print("started")
        print(x)
    }

It takes a while and then crashes.

enter image description here

Update 2: I was finally able to call the apis without getting a crash by adding Privacy - Motion Usage Description in info.plist. It would be really nice if I had an error message, I just guessed this this time.

However, I get no data and I get an Error. The block parameters x: [CMDeviceMotion]?, e: Error? gives me nil on the x and for the error I get:

"The operation couldn’t be completed. (CMErrorDomain error 109.)"

Journeywork answered 19/9, 2023 at 9:11 Comment(3)
Hard to tell what you are doing wrong without seeing your code. Please edit your question and include just enough code to allow others to reproduce the problem. For help with this, read How to create a Minimal, Reproducible Example.Danford
I'm just hoping someone tells me that they've gotten data from CMBatchedSensorManager at this point. Just so that I know the APIs are working and I'm doing something wrong. Have you done that?Journeywork
I'm new to swift and would like to try out out the new APIs. Would you mind posting a minimal ContentView file that initializes the CMBachedSensorManager? Or can anyone show their code? Thanks!Given
A
1

This is a workout centric API, this means that you need an active HealthKit workout session. Do you have one active when trying to get the batched sensor data?

Abstracted answered 21/9, 2023 at 15:4 Comment(1)
Thanks. You are right, I had forgotten about this. But still, I can't manage to get it working. I've updated the question with more details.Journeywork
J
1

You need

1 - Privacy - Motion Usage Description in info.plist

2 - HealthKit and active workout session

Journeywork answered 22/9, 2023 at 8:22 Comment(1)
Had the same crash while trying to use the accelerometer. Privacy - Motion Usage Description was missing from the info.plist (wasn't required in earlier iOS versions). Wish Apple provided more context instead of a crash. Searched for this answer for awhile.Decima

© 2022 - 2024 — McMap. All rights reserved.