I am working on an Apple Watch companion app to an existing live iOS app. I am utilizing the heart rate tracking for an active 'self-care' sauna session. I say self-care in quotes because it's more self-care than a workout activity, but it is closely blurring the lines between the two.
I have come to understand that if a session truly isn't a workout, then you should not use workoutSession.startActivity. However the app needs to function entirely like a workout would. This is not a meditation application. Sauna is actually just one of many activity types supported in the app.
I have tried using extended runtime session, and there have been numerous issues with doing so. It is not nearly as robust for the user. For example, the active session is not prioritized by the watch's CPU. Now playing is no longer functional. Heart rate is far more inconsistent, and this variable is as critical as if it were in a workout.
I have tried using HKWorkoutSession, however I worry the app will be rejected by doing so. This method works most accurately to collect the right data for the user, and prioritizes system resources as expected. The app can be moved to the background as expected and continue to communicate with the iOS app.
What is the best way to move forward here. It almost feels like I am operating in a grey area with no real solution in place. Any assistance is greatly appreciated as we would like to follow all guidelines while producing a high quality experience for our users.
Use HealthKit to enable your iOS and watchOS apps to work with the Apple Health app.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi everyone!
I'm trying to get the total sleep time for a given day, but users report that there's a difference between what my app reports and what the Apple Health app reports. In particular, we're off by 2 minutes less on average.
What we're doing is:
Get all the samples that are either core, deep, rem or unspecified
Cut-off time at 3 PM previous day
Merge overlapping intervals
Add all the remaining intervals
For debugging purposes I'm storing and sending all the raw samples to a server, and I have run tests and I don't find anything wrong. It looks like the number we come up with is correct according to our own rules. I wonder, how is Apple adding up all the samples to arrive at a number that's slightly off to our number.
Any insight would be appreciated. Thanks.
I am developing a React Native app for a health monitoring device that connects via Bluetooth and streams live data on iOS. To ensure the uniqueness of the device, I initially planned to use the MAC address. However, I discovered that iOS does not provide access to the original MAC address due to privacy restrictions.
Is there an alternative approach to uniquely identifying a Bluetooth device in iOS? I need a reliable way to distinguish devices while maintaining secure and stable connections.
Any insights or best practices on handling this in iOS would be greatly appreciated.
Looking forward to hearing your suggestions! If anyone has experience with handling Bluetooth device uniqueness on iOS, please share your insights. Thank you!
Topic:
App & System Services
SubTopic:
Core OS
Tags:
macOS
Health and Fitness
Core Bluetooth
Privacy
The WatchOS developer is not allowed to obtain healthKit permission status. The result is always unauthorized (either by clicking the dot/cross in the upper left corner or by turning on all Health, on some, off all).
WatchOS 开发获取 healthKit 的权限状态authorizationStatus不准。结果始终都是未授权(无论是点击左上角的点叉号还是开启全部健康项开关,开启部分,关闭所有),怎么处理?
Hello,
I’m developing an iOS app that works with sleep data from Apple Watch via HealthKit. I would like to clarify the following:
How can an iPhone app detect when a sleep session ends on the Apple Watch?
When is sleep data typically written to the HealthKit store on iPhone after sleep ends? Is it immediately after wake-up, or does it depend on certain conditions (e.g., watch charging, connectivity)?
Understanding the timing and mechanism of sleep data synchronization is crucial for our app to process accurate and timely health information.
Thank you for your assistance.
My research group is using watch sensors (accelerometers, gyroscopes) to track wrist motion to detect and measure eating. https://cecas.clemson.edu/ahoover/bite-counter/
We are running an HKWorkoutSession on the watch so that the app can run for an extended period of time (up to 12 hr) and continue to sense and process motion data.
Our app is adding to the activity rings, making it look like the user is exercising the entire time our app is running. Is there a method to prevent our app from contributing to the activity ring measures?
Topic:
App & System Services
SubTopic:
Health & Fitness
Tags:
WatchKit
Health and Fitness
SensorKit
WorkoutKit
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?
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 ?
Hi everyone,
I'm building a health-focused iOS and watchOS app that uses WatchConnectivity to sync real-time heart rate and core body temperature data from iPhone to Apple Watch. While the HealthKit integration works correctly on the iPhone side, I'm facing persistent issues with WatchConnectivity — the data either doesn't arrive on the Watch, or session(_:didReceiveMessage:) never gets triggered.
Here's the setup:
On iPhone: Using WCSession.default.sendMessage(_:replyHandler:errorHandler:) to send real-time values every few seconds.
On Apple Watch: Implemented WCSessionDelegate, and session(_:didReceiveMessage:) is supposed to update the UI.
Both apps have WCSession.isSupported() checks, activate the session, and assign delegates correctly.
The session state shows isPaired = true and isWatchAppInstalled = true.
Bluetooth and Wi-Fi are on, both devices are unlocked and nearby.
Despite all this, the Watch never receives messages in real-time. Sometimes, data comes through in bulk much later or not at all.
I've double-checked Info.plist configurations and made sure background modes include "Uses Bluetooth LE accessories" and "Background fetch" where appropriate.
I would really appreciate guidance on:
Best practices for reliable, low-latency message delivery with WatchConnectivity.
Debugging steps or sample code to validate message transmission and reception.
Any pitfalls related to UI updates from the delegate method.
Happy to share further details. Thanks in advance!
Topic:
App & System Services
SubTopic:
Networking
Tags:
Watch Connectivity
Health and Fitness
watchOS
Apple Watch
Hello everyone, my app is designed to help people sleep. It has been rejected multiple times due to issues with version 1.4.1 during the submission process. However, the app simply evaluates users’ insomnia and anxiety status based on their responses to questions and provides some relaxation methods. It does not involve any medical-related content. The reviewer provided screenshots of the assessment results page and some relaxation techniques. How should I handle this issue?
Hello everyone, my app is designed to help people sleep. It has been rejected multiple times due to issues with version 1.4.1 during the submission process. However, the app simply evaluates users’ insomnia and anxiety status based on their responses to questions and provides some relaxation methods. It does not involve any medical-related content. The reviewer provided screenshots of the assessment results page and some relaxation techniques. How should I handle this issue?
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
Hello everyone,
Ujjwal here, founder and CEO of a new iOS app in the mental wellness space.
Our mission is to provide accessible, AI-driven support for individuals dealing with anxiety, depression, and loneliness. From the very beginning, this has presented us with a unique and critical challenge: How do we effectively market an app to reach those who need it most, while upholding the absolute highest standards of user privacy?
We've built our app, ThunDroid, with a "privacy-by-design" philosophy. We leverage on-device processing for our core AI features, utilize end-to-end encryption, and have proudly integrated 'Sign in with Apple' to maximize user anonymity. We believe these are not just features, but ethical obligations to our users, especially given the nature of the data they trust us with.
The challenge, however, arises in marketing. This leads us to focus on mission-driven, organic marketing, but it's a slower path to reaching users who might be in immediate need of support.
This brings me to my question for this knowledgeable community.
What best practices or creative strategies have you found effective for marketing applications?
I appreciate any insights or experiences you're willing to share as we continue to grow ThunDroid responsibly.
Thank you for your time and consideration.
App Store link: (would love to hear your reviews)
[https://apps.apple.com/in/app/thundroid-ai-human-companion/id6746182736)
Topic:
App Store Distribution & Marketing
SubTopic:
General
Tags:
App Review
Health and Fitness
Marketing
Privacy
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