Post

Replies

Boosts

Views

Activity

HealthKit returns different values depending on the OS the request is made on
Hi, I've had trouble for a while now with HealthKit giving me different values if I make the request on iOS and WatchOS. I am using the exact same method on both with the same parameters but I get vast differences in the results. The code I am using to call HealthKit on both devices is: let dateRange = HKQuery.predicateForSamples(withStart: Date().removeMonths(numberOfMonths: 1), end: Date().endOfDay()) let predicate: NSPredicate predicate = NSCompoundPredicate(type: .and, subpredicates: [dateRange]) let query = HKStatisticsQuery(quantityType: HKQuantityType(.stepCount), quantitySamplePredicate: predicate, options: .cumulativeSum) { _, result, error in if error != nil { //print("Error fetching step count, or there is no data: \(error.localizedDescription), \(startDate) -> \(endDate)") onComplete(0) return } if let result, let sum = result.sumQuantity() { let stepCount = sum.doubleValue(for: HKUnit.count()) DispatchQueue.main.async { onComplete(Int(stepCount)) } } } healthStore.execute(query) }
4
0
1k
Jan ’25
WatchOS smart alarm using WKExtendedRuntimeSession
I’m developing a smart alarm app that makes use of the extended runtime session. I’ve looked at the docs, and one of the background modes for Apple watch is smart alarm. The docs also say that an extended runtime session can only be scheduled one at a time, and while the app is open, which isn’t very intuitive for an alarm app that runs on schedules. I’ve seen other apps do something similar, but I’m trying to make this fully automated, without the user having to do too much manually to reschedule the smart alarm. Is there no way to do this? I would’ve thought the smart alarm background modes would allow to schedule more than 1/a repeating extended runtime session.
0
0
42
8h