HealthKit

RSS for tag

Access and share health and fitness data while maintaining the user’s privacy and control using HealthKit.

HealthKit Documentation

Posts under HealthKit tag

106 Posts
Sort by:
Post not yet marked as solved
0 Replies
521 Views
I am creating a watch app that keeps track of the amount of time a user has been asleep for and then updates a game using an API in real time if they surpass another user's sleep time. They select who they want to surpass so the app knows the target time they want to sleep for. I know this probably sounds silly, it's not the final iteration of what I want to build but I know I will need this functionality. So I need this watch app to be able to update the game if they surpass the opponent while the user is sleeping. I don't think this is possible without using extended runtime sessions so that it can run in the background and check to see how long the user has been asleep for after the watch locks. As far as I know the extended runtime sessions only last for 30 minutes though. My current plan to deal with this is to reschedule the session using session.start(at: ) I am currently thinking about doing it like this: User selects opponent and goes to bed App gets the amount of time the user needs to sleep for to surpass opponent, "sleepTime" App schedules an extended runtime session to activate sleepTime seconds in the future sleepTime seconds in the future the session activates and the app checks to see how long the user has actually slept since they went to bed. If the user has slept less than the sleepTime needed to surpass the opponent the app will reschedule the extended runtime session for sleepTime - amountSleptSoFar == "sleepRemaining" seconds, in the future. sleepRemaining seconds in the future the session will activate and check to see how long the user has actually slept for again. If the user has slept less than the time needed to surpass the opponent then the session is rescheduled like before If the user has slept more than the time needed to surpass the opponent then the app uses an API to update the game. It is important that the game is updated as soon as the user surpasses an opponent and I don't want to set up a database to store sleep information and then update the game using the database data as soon as the database is updated. Does this seem like an okay approach? And more importantly is it possible to do? From what I've read and implemented so far it seems possible but please let me know if I'm missing something. The one thing I'm unsure about is if I can use session.start(at: ) when the app is not currently open. If I can't reschedule using that then how else could I do what I need to do?
Posted
by
Post not yet marked as solved
0 Replies
481 Views
I want to sync an object between iPhone and Apple Watch during a workout session, with the startMirroringToCompanionDevice function. It works fine if the class is no model, but as soon as I declare them as @Model, I get the problem that the JSON decoder creates a new Object. Now, SwiftData tries to insert these objects again. Is there another way to sync SwiftData objects? Or is there a way to create an object, which consists of multiple @Model objects, without the need to insert it instantly into the model context?
Posted
by
Post not yet marked as solved
0 Replies
333 Views
The "func workoutBuilder(_ workoutBuilder: HKLiveWorkoutBuilder, didCollectDataOf collectedTypes: Set)" function from the "HKLiveWorkoutBuilderDelegate" is not updating data from "HKQuantityType.quantityType(forIdentifier: .activeEnergyBurned)" in a workout session. My app is using the same code as before and it stopped working since I updated my watch to the version 9.6.1(20U80). I am using Xcode 14.3.1 (14E300c). Is there any solution to address this matter?
Posted
by
Post marked as solved
3 Replies
471 Views
I'm using Xcode Version 15.0 beta (15A5160n) and getting the following error: Value of type 'HKWorkoutSession' has no member 'sendToRemoteWorkoutSession' Any idea what's causing this? I pulled the code from https://developer.apple.com/videos/play/wwdc2023/10023/
Posted
by
Post not yet marked as solved
0 Replies
291 Views
Hi, i am developing an app to enter audiogram data to Apple HealthKit and i want to have a little more information about Apple‘s headphone accommodation. is there any information about how the accommodation exactly works? Which filters will be applied in the background? How are the filter coefficients created etc.? Is there any access to the resulting eq curve? Is there also dynamic compression used in a certain way? Kind regards, Tom
Posted
by
Post not yet marked as solved
1 Replies
357 Views
So almost every EPIC customer is now at a version that would allow their medical records to be imported, many of them just haven't filled out the Apple form to list their organization. EPIC does publish a list of the FHIR endpoints for all of these customers though. Functionally it should be possible to write an app that authenticates the user to their provider, and downloads the FHIR data from the API, and then pushes it into Apple Health. The two things I'm not clear on though are: Are the Medical Records available to write to from an app, or is it only available through organizations registered through Apple using their UI? Would Apple consider this a replication of their functionality as far as App Store T's & C's go?
Posted
by
Post marked as solved
2 Replies
1k Views
My app's Widgets on iPhone rely on access to the Health Store to update. This makes them appearing in the new StandBy mode not a good experience as they never update. Is there a way to opt out of this mode but keep the options for my users to put Widgets on their home screen? Thanks
Posted
by
Post marked as solved
1 Replies
493 Views
Hi, I am running the "Building a multidevice workout app" sample: https://developer.apple.com/documentation/healthkit/workouts_and_activity_rings/building_a_multidevice_workout_app I do not get any values for the .cyclingSpeed Value? Is this correct or should there be any value while moving around? Also i wonder if i can get the GPS values like altimeter or location from the HKWorkoutSession? Thanks
Posted
by
Post not yet marked as solved
3 Replies
617 Views
I am trying to get heart rate data from health store but when I make a query there are samples that come through with timestamps that shows that there are minutes that go by between the sample measurements. I remember watching an apple video where they were talking about the Quantity series and how these series have one kind of container for multiple data points of bpm data. I also see in the samples that there is a unit of " ___ counts per second" for each of the results so it would make sense if there were multiple datapoints within each of the results from the query but I don't know how to see what's inside of the results or if there is even anything more to them. This is the code I am using to retrieve the data: public func fetchLatestHeartRateSample(completion: @escaping (_ samples: [HKQuantitySample]?) -> Void) { /// Create sample type for the heart rate guard let sampleType = HKObjectType .quantityType(forIdentifier: .heartRate) else { completion(nil) return } /// Predicate for specifying start and end dates for the query let predicate = HKQuery .predicateForSamples( withStart: Date.distantPast, end: Date(), options: .strictEndDate) /// Set sorting by date. let sortDescriptor = NSSortDescriptor( key: HKSampleSortIdentifierStartDate, ascending: false) /// Create the query let query = HKSampleQuery( sampleType: sampleType, predicate: predicate, limit: Int(HKObjectQueryNoLimit), sortDescriptors: [sortDescriptor]) { ( _, results, error) in guard error == nil else { print("Error: \(error!.localizedDescription)") return } print(results ?? "Error printing results.") completion(results as? [HKQuantitySample]) } healthStore.execute(query) } Ultimately I want the most frequent heart rate data that is available. Ideally a bpm measurement every 5 - 10 seconds or less. Is this possible if I have not explicitly saved this heart rate data to the health store for a user before trying to access it or does Apple store all of this information in the health store regardless of the circumstances? Any help is greatly appreciated!
Posted
by
Post not yet marked as solved
0 Replies
396 Views
We have an app that reads data from the Apple Health Kit that is about 5 years old and we stopped receiving data from the app. While investigate why it quit working we are seeing some messages in the console log when we plug a phone into a mac that we are trying to get clarification on. We are seeing from the log: healthd 'STARTING: com.apple.healthkit.background-delivery.:<thread?>' followed by a: dasd 'COMPLETED com.apple.healthkit.background-delivery.:<thread?> at priority 30 then a dasd 'NO LONGER RUNNING com.apple.healthkit.background-delivery.:<thread?> ... Tasks running in the group [com.apple.dash.default] are 1! I was looking for some clarification on what these messages mean. Do they mean that our app was started and that the process completed successfully or, is it a warning saying that something abnormal happened. Also, I'm coming up short on documentation when I google for these messages. Is there a repository out there to help me make sense of what I'm seeing? Thanks for any insight!
Posted
by
Post not yet marked as solved
0 Replies
275 Views
Hello! I was wondering whether or not it was possible for: An application to programmatically open up an Apple app (i.e. navigate to the ECG app on the Apple Watch for my case) through some framework or internal URL? A background thread of my running application (which is occurring through a workout session) to issue a command to come back to it's main page of the application? This would help in a systematic data-gathering flow which requires me to gather ECG data and then return to the application for further action without too much action on the user's behalf. Thank you!
Posted
by
Post not yet marked as solved
4 Replies
959 Views
For some reason I am not receiving HKQuantityTypeIdentifierDistanceSwimming samples when using the watchOS 10 beta (8). The same code works fine on watchOS 9 but not on watchOS 10. I have tried specifically enabling them in the collection types for the live builder and /or starting a query for them, but neither approach is causing any samples to be returned to the app. Is this a known issue? Has something changed for swimming in watchOS 10? Thanks in advance.
Posted
by
cfc
Post not yet marked as solved
0 Replies
374 Views
Hey team! I have a question that feels very obvious, but I cannot seem to find the answer in the documentation. Using HealthKit/WorkoutKit, how you can make workouts with different activity types? Say you do 10 minutes of traditionalStrengthTraining followed by 10 minutes of running (common for crossfit and similar high intensity workout styles)? From the docs, it looks like you can’t change the activity type on an HKWorkout and the new dividing workouts into activities concept seems to only be for swimBikeRun workouts. Do you simply make multiple consecutive HKWorkoutSession instances, e.g doing startActivity -> beginCollection -> endCollection multiple times? Any input is highly appreciated!
Posted
by
Post marked as solved
1 Replies
508 Views
I am working with Apple HealthKit, and I need to add functionality to my app that allows a user's Apple Watch to automatically send the relevant data for their workout session (e.g. vo2 max, start timestamp, end timestamp, heartbeat, duration etc) as soon as they end their workout. This would need to work for any type of workout they do. E.g. if they are doing a running session, when they end their workout my app needs to receive the data for that running session almost instantly. I know that enableBackgroundDelivery allows my app to listen to changes in Apple Health in the background, but I'm not sure which method in HealthKit will allow me to implement the above use case. Does anyone have any pointers? I just want to know what methods in HealthKit will allow me to achieve this.
Posted
by
Post not yet marked as solved
0 Replies
386 Views
At the moment I am working on a small app that retrieves Activities via HealthKit and allows user to trim activities. A typical use case would be when an user forgets to finish / stop an activity recording on his watch. Has anyone experience with submit such kind of apps to the app store. Does apple even allow this kind of feature? It could harm the integrity of health data if not done correctly.
Posted
by
Post marked as Apple Recommended
682 Views
I am having trouble getting the new mirroring session API to send data to the companion device. when starting a workout on my watch I call startMirroringToCompanionDevice and then go onto my iOS workout manager to handle it via the workoutSessionMirroringStartHandler, I set the delegate here and can confirm that it is indeed not nil within that function but when I go to send some data across I get an error saying the remote session delegate was never set up. I noticed this same behaviour in the WWDC demo and have been unable to find a solution that will allow me to send data across the mirrored session even though I am able to control the workout session state(pause, resume, end) on both Phone and Watch. Has anyone else encountered this issue? Anyone have a solution?
Posted
by
Post marked as solved
1 Replies
507 Views
Hi Is there a way to read the sleep schedule i have set in either the health or clock apps? I found a few posts on here asking the same thing and the responce was always either no or just no responce but they are all from over 2 years ago so im not sure if something has changed since then. Up untill recently i was using a shortcuts automation to get the data but a recent update started excluding the sleep schedule alarm from the list that the shortcuts app can pull from the clock app. I dont want historical data, just when the alarm is set to go off next. I was using it to turn my lights on dim half an hour before the alarm goes off without having to set the schedule in 2 places. I have an annoyingly inconsistent morning schedule. Thanks
Posted
by