Post

Replies

Boosts

Views

Created

hkLiveWorkoutBuilder.statistics(for: heartRate) vs HKAnchoredObjectQuery when developing workout app
I'm making a workout app for Apple Watch. I start HKWorkoutSession, then associate it with HKLiveWorkoutBuilder and begin listening for heart rate and calorie changes. I have 2 options on how to get a heart rate or calories: Using HKLiveWorkoutBuilder statistics:  let heartRate = HKQuantityType.quantityType(forIdentifier: .heartRate),         let statistics = builder.statistics(for: heartRate){                   let heartRateUnit = HKUnit.count().unitDivided(by: HKUnit.minute())         let value = statistics.mostRecentQuantity()?.doubleValue(for: heartRateUnit) 2. Executing HKAnchoredObjectQuery: let heartRateSample = HKSampleType.quantityType(forIdentifier: HKQuantityTypeIdentifier.heartRate) let heartRateUnit = HKUnit.count().unitDivided(by: HKUnit.minute()) let updateHandler: (HKAnchoredObjectQuery, [HKSample]?, [HKDeletedObject]?, HKQueryAnchor?, Error?) - () = { query, newResult, deleted, newAnchor, error in if let samples = newResult as? [HKQuantitySample] { guard samples.count 0 else { return } for sample in samples { let value = sample.quantity.doubleValue(for: heartRateUnit) value = Int(value) } } } heartRateQuery = HKAnchoredObjectQuery(type: heartRateSample!, predicate: nil, anchor: nil, limit: Int(HKObjectQueryNoLimit), resultsHandler: updateHandler) heartRateQuery!.updateHandler = updateHandler store?.execute(heartRateQuery!) Which of the options is preferable? Are there any benefits of using one over another? Big thanks for all your responses!
1
0
712
May ’21
hkLiveWorkoutBuilder.statistics(for: heartRate) vs HKAnchoredObjectQuery when developing workout app
I'm making a workout app for Apple Watch. I start HKWorkoutSession, then associate it with HKLiveWorkoutBuilder and begin listening for heart rate and calorie changes. I have 2 options on how to get a heart rate or calories: Using HKLiveWorkoutBuilder statistics:  let heartRate = HKQuantityType.quantityType(forIdentifier: .heartRate),         let statistics = builder.statistics(for: heartRate){                   let heartRateUnit = HKUnit.count().unitDivided(by: HKUnit.minute())         let value = statistics.mostRecentQuantity()?.doubleValue(for: heartRateUnit) 2. Executing HKAnchoredObjectQuery: let heartRateSample = HKSampleType.quantityType(forIdentifier: HKQuantityTypeIdentifier.heartRate) let heartRateUnit = HKUnit.count().unitDivided(by: HKUnit.minute()) let updateHandler: (HKAnchoredObjectQuery, [HKSample]?, [HKDeletedObject]?, HKQueryAnchor?, Error?) - () = { query, newResult, deleted, newAnchor, error in if let samples = newResult as? [HKQuantitySample] { guard samples.count 0 else { return } for sample in samples { let value = sample.quantity.doubleValue(for: heartRateUnit) value = Int(value) } } } heartRateQuery = HKAnchoredObjectQuery(type: heartRateSample!, predicate: nil, anchor: nil, limit: Int(HKObjectQueryNoLimit), resultsHandler: updateHandler) heartRateQuery!.updateHandler = updateHandler store?.execute(heartRateQuery!) Which of the options is preferable? Are there any benefits of using one over another? Big thanks for all your responses!
Replies
1
Boosts
0
Views
712
Activity
May ’21
StartWorkoutIntent Example in Swift
How to read the physical Action button of the Apple Watch Ultra? I found some partial info that will be a part of StarWorkoutIntent. Does anyone have a working example of how to implement StartWorkoutIntent and integrate it into a fitness app?
Replies
1
Boosts
0
Views
927
Activity
Sep ’22
MacOs Ventura: "Login item added" pops up on every computer reboot
I'm developing an app which has "Launch on startup" settings. On MacOS Monterey, "Launch on startup" worked just fine. On MacOS Ventura, on every laptop reboot "Login item added" pops up. Isn't it suppose to be just once? Is there a way to prevent the pop up appearance every reboot? P.S. I also filed a bug report FB11625758
Replies
1
Boosts
0
Views
1.5k
Activity
Sep ’22