HealthKit data duplicity concerns - ios

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.. :)

Related

Apple Health Kit Data via Rest API

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.

Apple Health: export health data automatically

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.

Online Data Storage and Transfer with Swift

I am trying to make a series of applications which require the user to make an account and login, therefore they could use the application on multiple devices and have the same data (e.g.. amount of virtual money and player score is about it), however, I have no idea how to go about this, I have decided it would be best for my app not use the apple GameKit (game centre) as it has a lot of limitations (e.g not showing usernames). What methods could I use to do this? Do I need to learn another language
Thank you
You can try Firebase, which serves as a backend especially for mobile applications. Basically, send a kind of a POST request to Firebase when the values you want to store have been changed in your game and send a kind of a GET request to fetch the said values to your mobile app(s). By this way, you can store data on Firebase and fetch it via multiple devices when the same user logs in from different devices.
For more information and a quick start, check this link: https://www.firebase.com/docs/ios/quickstart.html

Query HealthKit for list of existing WRITE permissions?

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

Apple Watch - Example on how to get heart rate data?

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....

Resources