For an app that plan to integrate Apple HealthKit to allow app users to upload and download their health data, where can I locate the Data Processing Addendum that specifies who the data controller and processor will be, and how such health data will be used or distributed?
Health & Fitness
RSS for tagExplore the technical aspects of health and fitness features, including sensor data acquisition, health data processing, and integration with the HealthKit framework.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Based on Cooordinate with the companion app in this article by Apple
https://developer.apple.com/documentation/healthkit/running-workout-sessions
if a workout were to be started on the iPhone companion app but with no Watch available, given HKLiveWorkoutBuilder not available in iOS, does the iPhone app need to implement it's own workout tracking such as a timer for counting the elapsed time and location updates for distance and GPS tracking?
If so in an instance where a paired Apple Watch were to exist and the workout is continued in the Watch app should the iPhone companion app stop this custom workout tracking and revert to the mirrored workout from the Watch to ensure accurate and synchronised data between the apps?
读取是不是解析 metadata 的对应键来获取值对吧~但我看了相关开发文档好像没找到这个的键是什么~于是也没法写入到对应的,现在只能自定义键来进行写入
但是这样写入后无法显示在心情下方的影响因素后面~
这个 key 是没公开的吗还是说我方法弄错了~请各位大大指教
We are working on the health related application and use apple health kit to sync the data from different devices like watches or ring.
We are targeting oura ring to get sleep and other parameters data. We are able to sync the data from oura for all other parameters (like pulse, respiratory rate, blood pressure, etc..) other than sleep. Surprisingly, sleep data that comes through other devices is syncing as expected from the health kit. We are even getting the data which is added manually in health kit. The only sleep data not syncing is from oura.
Can we get a document or any kind of help to sync the data from oura in to our application using health kit?
In general my workout app is reachable from the iPhone when running a workout, even if in the background. However if the watch app restarts (due to crash or being closed via the dock) via handleActiveWorkoutRecovery then it is only reachable when in the foreground, even though a workout is running.
Is this expected / desired behaviour? Is the app given a tighter sandbox (having it's "background privileges" reduced) because of the earlier crash?
This behaviour occasionally happens without a crash (or being closed via the dock) - all of a sudden it is no longer reachable via the iPhone. It feels like the app is being "sandboxed" like in #1 but there is no crash or any other kind of log indicating any issue. Generally the only remedy is to stop the workout and restart the app. My question is - is this expected? Is there some condition that causes the watchOS to sandbox the app? Or is this a Watch Connectivity bug?
I'm reading hourly statistics from HealthKit using executeStatisticsCollectionQuery (code below).
Expectation
What I expect is to get back the list with one row per hour, where each hours has the same cumulative sum value.
Actual result
In results, first hour always contains less calories than next hours, which all have the same value.
Example:
Start: 2025-06-02T00:00:00+03:00, anchor: 2025-06-02T00:00:00+03:00, end: 2025-06-02T12:00:00+03:00
🟡 2025-06-02T00:00:00+03:00 Optional(50.3986 kcal)
🟡 2025-06-02T01:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T02:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T03:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T04:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T05:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T06:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T07:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T08:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T09:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T10:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T11:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T12:00:00+03:00 Optional(14.0224 kcal)
As you can see, here we have 2025-06-02T00:00:00+03:00 Optional(50.3986 kcal)
Now, if I add one more hour to the request (from beginning of time window), the same hour has proper calories count, while newly added hour, has wrong value):
2025-06-01T23:00:00+03:00, anchor: 2025-06-01T23:00:00+03:00, end: 2025-06-02T12:00:00+03:00.
🟡 2025-06-01T23:00:00+03:00 Optional(50.3986 kcal)
🟡 2025-06-02T00:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T01:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T02:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T03:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T04:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T05:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T06:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T07:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T08:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T09:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T10:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T11:00:00+03:00 Optional(64.421 kcal)
🟡 2025-06-02T12:00:00+03:00 Optional(14.0224 kcal)
And now first hour of the day, magically has more calories burned: 2025-06-02T00:00:00+03:00 Optional(64.421 kcal)
I suspect similar things happen with other quantity types, but haven't yet found a way to reproduce it.
Am I doing something wrong or is it a bug in HealthKit?
Code
let anchorDate = startDate
let predicate = HKQuery.predicateForSamples(withStart: startDate, end: endDate, options: [.strictStartDate])
healthStore.executeStatisticsCollectionQuery(
quantityType: .basalEnergyBurned,
quantitySamplePredicate: predicate,
options: [.separateBySource, .cumulativeSum],
anchorDate: anchorDate,
intervalComponents: DateComponents(hour: 1),
initialResultsHandler: { statistics, error in
if let error = error {
log(.error, "Error retrieving steps: \(error.localizedDescription)")
continuation.resume(throwing: SpikeException("Error retrieving steps: \(error.localizedDescription)"))
return
}
if let statistics {
let f = ISO8601DateFormatter()
f.timeZone = TimeZone.current
for s in statistics {
log(.debug, "\(f.string(from: s.startDate)) \(s.sumQuantity())")
}
}
continuation.resume(returning: statistics ?? [])
}
)
I want to know , how many days will the data of health stays in apple watch . For example, I have not synced the watch with iPhone for two weeks . Then When I synced it , I am only able to see the last week data on iPhone of the watch . Is it true ?
I am experiencing a critical issue with HealthKit authorization in iOS 18.5 where requestAuthorization() calls are immediately denied without showing the user permission dialog.
Problem Description:
HealthKit authorization requests immediately return .sharingDenied status
No system permission dialog is displayed to the user
Authorization status changes from .notDetermined to .sharingDenied in <0.1 seconds
This occurs for all HealthKit data types (step count, heart rate, sleep analysis, etc.)
Technical Details:
iOS Version: 18.5 (22F76)
Xcode Version: 16F6
Device: iPhone (tested on both simulator and physical device)
Bundle IDs tested: com.hereforyou.test2024, com.hereforyou.app
Entitlements: com.apple.developer.healthkit = true
Code Implementation:
let healthStore = HKHealthStore()
let stepType = HKObjectType.quantityType(forIdentifier: .stepCount)!
// Status before request: .notDetermined
try await healthStore.requestAuthorization(toShare: [], read: [stepType])
// Status after request: .sharingDenied (immediate, <0.1 seconds)
Evidence this is not a code issue:
Other HealthKit apps from App Store work correctly on the same device
Proper entitlements are configured and verified
HKHealthStore.isHealthDataAvailable() returns true
Same code worked in previous iOS versions
Multiple Bundle IDs tested with same result
Expected Behavior:
System should display HealthKit permission dialog allowing user to grant/deny access
Actual Behavior:
Authorization is immediately denied without user interaction
Steps to Reproduce:
Create new iOS app with HealthKit entitlements
Call requestAuthorization() for any HealthKit data type
Observe immediate denial without permission dialog
Is this a known issue in iOS 18.5? Are there any workarounds or timeline for a fix?
Best regards
Topic:
App & System Services
SubTopic:
Health & Fitness
How to launch companion Watch App without relying on Health Kit?
I need my companion watch to launch automatically in some specific cases. What I'm doing to achieve that is to call "startWatchApp" in HKHealthStore().
This worked flawlessly for well over a year but AppReview is now giving me a hard time about using HealthKit without actually using health related data.
Is there a way to do the same without using HealthKit? Seems silly that this is bundled only with the HealthKit...
If I don't find another solution I will probably be forced to start reading heart rate data and reporting it to the user just so that AppReview will stop saying that I have no reason to use HealthKit... But ideally I'd love to learn about a way to open the companion Watch app without HealthKit and do things the right way...
Hi y’all! This is my first post but I wanted to ask if anyone else has had this happen and fixed it. But I have lost 3 years of fitness and health data upon upgrading to iOS 26 beta 1. I have about 2 gigs of health data in iCloud which I’m praying to Tim is my data lol. But I was wondering if anyone else went through this issue on their test device and yeah.
Topic:
App & System Services
SubTopic:
Health & Fitness
Hi all,
I’m currently running watchOS 26 beta and have been experiencing several sensor-related issues since updating:
• Raise to Wake function doesn’t activate reliably or at all.
• Heart rate sensor fails to measure or shows inconsistent readings.
• Location services are not working properly, affecting workout tracking and apps that rely on GPS.
• Blood oxygen (SpO2) measurements are failing or missing completely.
I’m not sure exactly when these issues began, but they started after installing the latest beta. I’ve tried restarting and resetting but the problems persist. Has anyone else encountered similar issues? Any insights or fixes would be appreciated!
Thanks!
Topic:
App & System Services
SubTopic:
Health & Fitness
Has anyone had success using the HKWorkoutRouteBuilder in conjunction with the new iOS support for HKLiveWorkoutBuilder?
I was running my watchOS code that worked now brought over to iOS and when I call insertRouteData the function never returns. This happens for both the legacy and closure based block patterns.
private var workoutSession: HKWorkoutSession?
private var workoutBuilder: HKLiveWorkoutBuilder?
private var serviceSession: CLServiceSession?
private var workoutRouteBuilder: HKWorkoutRouteBuilder?
private func startRouteBuilder() {
Task { @MainActor in
self.serviceSession = CLServiceSession(authorization: .whenInUse)
self.workoutRouteBuilder = self.workoutBuilder?.seriesBuilder(for: .workoutRoute()) as? HKWorkoutRouteBuilder
self.locationUpdateTask = Task {
do {
for try await update in CLLocationUpdate.liveUpdates(.fitness) {
if let location = update.location {
self.logger.notice(#function, metadata: [
"location": .stringConvertible(location)
])
try await self.workoutRouteBuilder?.insertRouteData([location])
self.logger.notice("Added location")
}
}
} catch {
self.logger.error(#function, metadata: [
"error": .stringConvertible(error.localizedDescription)
])
}
}
}
}
I did also try CLLocationManager API with delegate which is what my current watch code uses (a bit old). Same issue.
Here is what I've found so far:
If the workout session is not running, and if the builder hasn't started collection yet, inserting route data works just fine
I've tried different swift language modes, flipped from main actor to non isolated project settings (Xcode 26)
Modified Apple's sample code and added location route building to that and reproduced the error, modified sample attached to feedback
This issue was identified against Xcode 26 beta 2 and iPhone 16 Pro simulator. Works as expected on my iPhone 13 Pro beta 2.
FB18603581 - HealthKit: HKWorkoutRouteBuilder insert call within CLLocationUpdate task never returns
Topic:
App & System Services
SubTopic:
Health & Fitness
Tags:
Beta
Health and Fitness
HealthKit
WorkoutKit
I'm using following filters to fetch swimming activities from HealthKit.
For some users it fetches all workouts (pool && open water) but for other it skips some open water activities. See screenshot, all those swimming activities are not fetched by following code.
let startDate = Calendar.current.date(byAdding: .month, value: -1, to: Date())!
let endDate = Date()
let swimmingPredicate = HKQuery.predicateForWorkouts(with: .swimming)
let timePredicate = HKQuery.predicateForSamples(withStart: startDate, end: endDate, options: .strictStartDate)
let predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [swimmingPredicate, timePredicate])
let query = HKSampleQuery(sampleType: .workoutType(),
predicate: predicate,
limit: HKObjectQueryNoLimit,
sortDescriptors: [.init(keyPath: \HKSample.startDate, ascending: false)],
resultsHandler: { [weak self] query, samples, error in
...
Could someone help with ideads what is missing in this case?
In iOS 26, HKLiveWorkoutBuilder is supported, which we can use like HKWorkoutSession in watchOS - this is very exciting.
However, it currently seems to have a bug in calculating calories.
I tested it in my app, and for nearly 6 minutes with an average heart rate of 134, it only calculated 8 calories consumed (80 calories per hour), including basal consumption, which is obviously incorrect.
(I used Powerboats Pro 2 connected to my phone, which includes heart rate data, and HKLiveWorkoutBuilder correctly collected the heart rate, which is great.)
I think my code is correct.
func workoutBuilder(_ workoutBuilder: HKLiveWorkoutBuilder, didCollectDataOf collectedTypes: Set<HKSampleType>) {
for type in collectedTypes {
guard let quantityType = type as? HKQuantityType else {
return // Nothing to do.
}
let statistics = workoutBuilder.statistics(for: quantityType)
if let statistics = statistics {
switch statistics.quantityType {
case HKQuantityType.quantityType(forIdentifier: .heartRate):
/// - Tag: SetLabel
let heartRateUnit = HKUnit.count().unitDivided(by: HKUnit.minute())
let value = statistics.mostRecentQuantity()?.doubleValue(for: heartRateUnit)
let roundedValue = Double( round( 1 * value! ) / 1 )
if let avg = statistics.averageQuantity()?.doubleValue(for: heartRateUnit) {
self.avgHeartRate = avg
}
self.delegate?.didUpdateHeartBeat(self, heartBeat: Int(roundedValue))
case HKQuantityType.quantityType(forIdentifier: .activeEnergyBurned):
let energyUnit = HKUnit.kilocalorie()
let value = statistics.sumQuantity()?.doubleValue(for: energyUnit)
self.totalActiveEnergyBurned = Double(value!)
print("didUpdate totalActiveEnergyBurned: \(self.totalActiveEnergyBurned)")
self.delegate?.didUpdateEnergyBurned(self, totalEnergy: self.totalActiveEnergyBurned + self.totalBasalEneryBurned)
return
case HKQuantityType.quantityType(forIdentifier: .basalEnergyBurned):
let energyUnit = HKUnit.kilocalorie()
let value = statistics.sumQuantity()?.doubleValue(for: energyUnit)
self.totalBasalEneryBurned = Double(value!)
print("didUpdate totalBasalEneryBurned: \(self.totalBasalEneryBurned)")
self.delegate?.didUpdateEnergyBurned(self, totalEnergy: self.totalActiveEnergyBurned + self.totalBasalEneryBurned)
return
default:
print("unhandled quantityType=\(statistics.quantityType) when processing statistics")
return
}
}
I think I've found the source of the problem:
let workoutConfiguration = HKWorkoutConfiguration()
workoutConfiguration.activityType = .traditionalStrengthTraining //walking, running is ok
workoutConfiguration.locationType = .outdoor
When I set the activityType to walking or running, the calorie results are correct, showing several hundred calories per hour.
However, when activityType is set to traditionalStrengthTraining or jumprope, the calculations are incorrect.
PS:
I'm currently using Xcode 26 beta3 and iOS 26 beta3.
Hope this issue can be resolved. Thanks.
Hello,
What is the best practice for sending customized workouts to the Apple Watch.
For example, sending a running workout that entails:
Run 1 mile at 8:00/mile
Walk 2 minutes
Run 2 mile at 7:00/mile ----
Walk 2 minutes ----
Repeat 2x
Run 1 mile at 8:00/mile
Any documentation or sample codes would be amazing. Thank you
Looking for help with our Apple HealthKit integration. We've successfully pulled steps, distance, active energy, glucose and heart rate. However, the data pulled for sleep duration is incorrect. Not sure what we're doing wrong.
Hi,
My app concept features various sections;
a) Personal development section: featuring exercises and guides,
b) Coaches section: featuring coaching sessions offering virtual or in-person sessions related to yoga, fitness, lifestyle etc. (marketplace for coaches).
c) Events section: hosting virtual or in-person events.
Hence which "tax category" should I be selecting?
Thanks,
Gavin
Topic:
App & System Services
SubTopic:
Health & Fitness
I updated my watch to take advantage of the reactivated blood oxygen/O2 function, but with my iPhone on public beta 3, it still shows unavailable. Will there be an update to beta three to allow this newly reactivated Apple Watch feature to function?
Are there any HealthKit related changes to be aware of in the new update that enables SPO2 / Blood Oxygen Saturation measurements on certain Apple Watch models within the US?
I’m aware of processing happening on the phone…. But beyond that:
Does this mean values are then saved to Apple Health?
Do these models still take background SPO2 measurements in the same way as other models do?
Are these values then visible in third party iOS apps as normal through HealthKit?
Do these values sync back to the paired Apple Watch HealthKit store for third party apps to access on the Watch?
For reference I have an iOS and WatchOS app that, amongst other features, provides the ability to see your SPO2 values in the Watch app, complications and in the iOS app.
Topic:
App & System Services
SubTopic:
Health & Fitness
Tags:
WatchKit
Health and Fitness
watchOS
HealthKit
If a user selects custom structured workout in the apple watch Workout app and records a run with intervals, how can my third party app pull in that data?
I can obviously get the workout and health stuff like heart rate, but I cannot find how to save the intervals and the relevant data.
The workout events are not seemingly helpful - segments are not obviously related to this.
Is it possible? Is it only possible to have the third party app create a customworkout with metadata and then our third party app parses the interval distance/time based on our own structure?
I think this stuff should be able to be accessed.