What's new in Core Motion

RSS for tag

Discuss the WWDC23 Session What's new in Core Motion

Posts under wwdc2023-10179 tag

2 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

How to use CMBatchedSensorManager
"for try await dataArray in bsm.deviceMotionUpdates()" generate error: Error Domain=CMErrorDomain Code=109 "(null)" Environment iOS 17.0 (21A5277j) watchOS 10.0 (21R5295g) XCode 15.0 beta 4 (15A5195m) Mac Studio 2022, macOS 13.4.1 (22F82) Details I create a swift project with code: File 1: let healthStore = HKHealthStore() var workoutSession: HKWorkoutSession! func workoutSession(_ workoutSession: HKWorkoutSession, didChangeTo toState: HKWorkoutSessionState, from fromState: HKWorkoutSessionState, date: Date) { } func workoutSession(_ workoutSession: HKWorkoutSession, didFailWithError error: Error) { } func requestAuthorization() { // The quantity type to write to the health store. let typesToShare: Set = [ HKQuantityType.workoutType() ] // The quantity types to read from the health store. let typesToRead: Set = [ HKQuantityType.quantityType(forIdentifier: .heartRate)!, HKQuantityType.quantityType(forIdentifier: .activeEnergyBurned)!, HKQuantityType.quantityType(forIdentifier: .distanceWalkingRunning)! ] // Request authorization for those quantity types healthStore.requestAuthorization(toShare: typesToShare, read: typesToRead) { success, error in // Handle error. } } // before call startWatch(), will request authorization to access Healthkit func startWatch(_ startWatchFor:Int) -> MotionManager? { let configuration = HKWorkoutConfiguration() let motionMgr: MotionManager? configuration.activityType = .golf configuration.locationType = .outdoor do { workoutSession = try HKWorkoutSession(healthStore: healthStore, configuration: configuration) workoutSession.startActivity(with: Date()) } catch { // Handle any exceptions. return nil } workoutSession.delegate = self ... // in turn, a func startUpdates() in another swift file will be called. } File 2: var batchedSensorManager: Any? @available(watchOSApplicationExtension 6.0.0, *) func batchedSensorUpdates() async { if #available(watchOSApplicationExtension 10.0, *), let bsm = batchedSensorManager as? CMBatchedSensorManager { bsm.startDeviceMotionUpdates() do { for try await dataArray in bsm.deviceMotionUpdates() { if !processDMEntry { break } ... // process data } } catch let error as NSError { print("batchedSensorManager.deviceMotionUpdates() fail", error.description) } } }
1
0
642
Jul ’23
Issue with accelerometerUpdates() function in CMBatchedSensorManager
I recently updated my iPhone to iOS 17.0 (21A5248v) and my Apple Watch Series 8 to watchOS 10.0 (21R5275t). I'm working with the CMBatchedSensorManager and have confirmed that the authorizationStatus is authorized. Additionally, both isDeviceMotionSupported and isAccelerometerSupported properties return true. However, when I call the startAccelerometerFetching() function shown below: @available(watchOS 10.0, *) func startAccelerometerFetching() async { do { for try await accelerometerList in batchedSensorManager.accelerometerUpdates() { accelerometerList.forEach { self.processAccelerometer($0) } } } catch let error as NSError { print("Encountered Error: \(error.userInfo) \(error.localizedDescription) -> \(error.code) \(error.localizedFailureReason)") } } I receive the following error message: "Encountered Error: [:] The operation couldn’t be completed. (CMErrorDomain error 109.) -> 109 nil" Does error code 109 correspond to CMErrorNotAvailable? How to solve this problem?
2
0
927
Aug ’23