Apple recently made heart hate raw data avaliable through healthkit, but the documentation is very confusing and I can not understand exactly how to measure the heartbeat of someone wearing the watch. I could not find any good examples on the internet either, so I'm hoping that someone could help me understand how can I get these values in a easy way.
The key is to check out HealthKit, not WatchKit. From the docs:
Setting Up HealthKit
Before you can begin using HealthKit, you must perform the following steps:
Enable the HealthKit capabilities in Xcode.
Check to see whether HealthKit is available by calling the isHealthDataAvailable method. HealthKit is not available on iPad. Additionally, HealthKit can be disabled on other devices—for example, iPhones that are provisioned for schools or corporate environments.
Instantiate an HKHealthStore object for your app. You need only one HealthKit store per app. This store acts as your primary interface with the HealthKit database.
Request authorization to access HealthKit data using the requestAuthorizationToShareTypes:readTypes:completion: method. HealthKit requires fine-grained authorization. You must request permission to share and read each type of data.
Etc....
Related
Are there any third party which provide data of apple health kit data using there end points like google fit provide us via rest api's https://developers.google.com/fit/rest/v1/get-started
No, there are not.
And there most likely won't be in the future either. This is an easy conclusion to make given how Health Kit integration works today and how Apple has privacy protocols around Health Data -
Integrating Health Kit in your app allows you to see Health Data only after the user has granted relevant permissions (of course). But the user has to explicitly grant permission for each datatype (HKObjectType) eg sleepAnalysis, blood glucose etc.
Your app with Health Kit integration can only request Health Data while the app is active in the background and the phone is not locked or running in the foreground. So lets say you have background tasks (BGAppRefreshTask or BGProcessingTask) to request Health Data - this won't work if your phone is locked.
Given these behaviours and other restrictions Apple places around the use of HealthKit, I don't see how there is ever (or at least in the near future) going to be a an api to relay this data.
If you absolutely had to it, your best bet would be to write an application on the device that integrates with HealthKit and exports HealthData to your servers. Then explicitly prompt the user to export HealthData from the app every time, and expose an api from your server. Not happening.
I am trying to export the health data from my iPhone/Apple Watch automatically. I know it is possible to export the data manually by opening the Health app on your iPhone > clicking the user icon > "Export Health Data". However, I would like to do this automatically and periodically to analyze the data (heart rate, steps, etc.) externally in Python. Is this possible at all?
To access any of your health data stored in Apple Health, you need to add the HealthKit framework to your iOS app by enabling HealthKit capabilities in Xcode. By using certain methods you can request permission from your iPhone to read and write data with your app.
To actually get the data you need to access it by using direct method calls, queries, or long-running queries – depending on how you want to retrieve the data and how background retrieval might work.
There is an "Apple Native way" to do that, This link has a comprehensive step-by-step guide (mainly but not exclusively for iOS developers). The drawback is that you can only integrate HealthKit into iOS applications and need to use iOS SDK 8 or higher.
I understanding from the WWDC video that the HealthKit API does not allow apps to query what measures they are allowed to read, but I was under the impression the Health Kit API does allow users to query Health Kit for what kinds of data they are allowed to write. However I have not been able to find the command to do this. Where is this info listed in the docs? Thanks for any suggestions.
You can determine your app's authorization status by calling authorizationStatusForType: on an HKHealthStore instance. See the documentation here
I'm writing an iOS app to display real-time Heart Rate from a BTLE device (the Polar H7). I've found 2 ways to do this:
Using CBCentralManager and bit-twiddling the Heart Rate Measurement Characteristic by hand
Using HealthKit's HKObserverQuery
As I see it, there are pros/cons to each approach.
Using CBCentralManager enables more control (e.g., you can store the sensor location) and quicker setup (i.e., you can start displaying values immediately). But, from what I can tell, the BTLE device will not be seen by CBCentralManager if the BTLE device is already paired with HealthKit.
Using HealthKit appears to be the preferred approach (and is much simpler to implement) but requires an extra trip to the Health app to turn on the "Update Health Data" switch.
Should I implement both? Has anyone dealt with this issue?
I haven't dealt with your issue specifically, but I am working on HealthKit integration as well. Based on what you've outline here, I would go with the HealthKit approach and only that approach unless there's some requirement to really push you do to both. If you do have to implement both, I would probably put some abstraction in there so the controllers don't have to know what the source is.
I'm not sure about the extra trip to the Health app you mention. You can ask for permission to the heart rate data from within your app using requestAuthorizationToShareTypes:readTypes:completion:. Here's a tutorial that has a walk through, in case that helps at all: HealthKit Tutorial with Swift: Getting Started.
I have an app which reads data from Strava, Runkeeper and couple of other health apps.
Now I am planning to integrate HealthKit in my app and read data from there as well.
My concern is data duplicity. i.e. say Strava sharing same data to my app and Healthkit, and then my app updating same data from HealthKit.
Not sure if this is allowed due to privacy concerns or not, Is there any way my app can know what all apps share data with HealthKit, preferably date range and type of data as well.
OR
Do I need to build the comparison logic in my app itself to detect duplicate data based on date and actual data?
The best way to do this with the HealthKit API is to simply not process data that comes from providers that your app can already integrate with. Every HKObject has an HKSource property, and that HKSource will give you the bundle identifier of the application that created it. You can use this to create a blacklist of sources to reject from HealthKit.
HealthKit framework is a centralized store for health data among various applications with in the iPhone device. So, all the health apps can share health data with HealthKit store.
For your case, there may be possibly 2 solutions available.
Simply stop updating health data from all other health apps like Strava, RunKeeper, etc., and read same information from Apple's HEALTH app to avoid duplicate records.
Read health data from all other health apps which you would prefer and omit the health data fetching from Apple's HEALTH app, which was entered from Strava, RunKeeper, etc., Sample to get the health data based on source is https://stackoverflow.com/a/29346592/1295573
Yes you can do this with health kit.
The HealthKit store provides a number of methods for accessing its data.
Direct method calls
Sample query
Observer query
Anchored object query
Statistics query
Statistics collection query
Correlation query
Source query
For more details go through https://developer.apple.com/library/ios/documentation/HealthKit/Reference/HealthKit_Framework/..
let me know if you get stuck somewhere.. :)