What's new in Core Motion

RSS for tag

Discuss the WWDC23 Session What's new in Core Motion

View Session

Posts under wwdc2023-10179 tag

3 Posts
Sort by:
Post not yet marked as solved
2 Replies
835 Views
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?
Posted Last updated
.
Post not yet marked as solved
0 Replies
556 Views
"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) } } }
Posted
by ATMooee.
Last updated
.
Post not yet marked as solved
0 Replies
615 Views
Good day, Fist I have to be honest. I was not developing for iOS for years, while I wanted to get back to if for quite some time. I started looking into CMWaterSubmresionManager documentation and I simply couldn't make it work. Then I got back to iOS basics to refresh my knowledge. I remembered and learned quite a few things, but still after hours and hours of trying and following various similar other Manager use. I still am not able to make any sense how to get CMWaterSubmresionManager delegate to work. My goal is very very simple - new Xcode project for watchOS app, witch companion app, which would allow me to capture info like water temperature, time underwater etc. I went through the documentation and did set all the prerequisites, like added authorisation for motion data, extended runtime session etc as per documentation: https://developer.apple.com/documentation/coremotion/accessing_submersion_data funny enough tried to start monitoring for data in the view. Obviously could set submersionManager.delegate = self, as it "Cannot find 'self' in scope;". Created a class, but could not call it (sorry can't remember the error already) and finally went through "Build a workout app for Apple Watch" ( https://developer.apple.com/wwdc21/10009 ) trying to setup CMWaterSubmerionManager similarly to WorkoutManager and got stuck on on EnviromentalObject Observable something error, which likely does not make any difference, because no such was mentioned anywhere in CMWaterSubmersionManager documentation. I tried to revert from Enviroment object but eventually getting "Constant 'submersionManager' captured by a closure before being initialized", which makes me thing I messed up in so many ways, I cant even track back. I am totally stuck and can't find any info anywhere on internet, no samples, nothing anywhere. If anyone could help making it work, I would be very grateful. My SumbersionManager file looks like: import CoreMotion import WatchKit class SubmersionManager: NSObject, CMWaterSubmersionManagerDelegate, WKExtendedRuntimeSessionDelegate { func extendedRuntimeSession(_ extendedRuntimeSession: WKExtendedRuntimeSession, didInvalidateWith reason: WKExtendedRuntimeSessionInvalidationReason, error: Error?) { print("extended session did error") } func extendedRuntimeSessionDidStart(_ extendedRuntimeSession: WKExtendedRuntimeSession) { print("extended session did START") } func extendedRuntimeSessionWillExpire(_ extendedRuntimeSession: WKExtendedRuntimeSession) { print("extended session did EXPIRE") } func manager(_ manager: CMWaterSubmersionManager, didUpdate event: CMWaterSubmersionEvent) { print("didSubmerge??") } func manager(_ manager: CMWaterSubmersionManager, didUpdate measurement: CMWaterSubmersionMeasurement) { print("someMeasurement") } func manager(_ manager: CMWaterSubmersionManager, didUpdate measurement: CMWaterTemperature) { print("some temperature") } func manager(_ manager: CMWaterSubmersionManager, errorOccurred error: Error) { print("some error") } func testSinc () { guard CMWaterSubmersionManager.waterSubmersionAvailable else { return } // Instantiate the submersion manager. let submersionManager = CMWaterSubmersionManager() // Assign the submersion manager delegate. submersionManager.delegate = self } func myStartDiveSession() { // logger.info("*** Starting a dive session. ***") print("*** Starting a dive session. ***") // Create the extended runtime session. let session = WKExtendedRuntimeSession() // Assign a delegate to the session. session.delegate = self // Start the session. session.start() } } nonisolated func manager(_ manager: CMWaterSubmersionManager, didUpdate event: CMWaterSubmersionEvent) { let submerged: Bool? switch event.state { case .unknown: submerged = nil case .notSubmerged: submerged = false case .submerged: print("submerged!!!!!!!!!") submerged = true @unknown default: } Task { if let submerged { print("submerged!!!!") } } } // Respond to errors. nonisolated func manager(_ manager: CMWaterSubmersionManager, errorOccurred error: Error) { } And I am simply trying to call it from view by initializing let submersionManager : SubmersionManager and .onAppear() { print("appeared in view") submersionManager.myStartDiveSession() OR submersionManager.testSync() "and getting mentioned captured by a closure before being initialized" error
Posted
by wza180.
Last updated
.