Health Kit APIs are designed to work with existing Health Apps, with this API app can share statistical analysis (e.g; graphs, trends..), user information etc.. and user can check it from iOS "Health" app
With Health Kit API we can create, save and ask for users health and fitness related data which is centrally managed by iOS "Health" app. This can be used for surfacing data from other health app and read/write your own data. There are some basics we need to know to get started with the same;
We can use HKStatics to get required quantity data from the query output, we can ask statictics for all kinda data or a particular HKSource data. There are two kinda quantity data, i.e;
With Health Kit API we can create, save and ask for users health and fitness related data which is centrally managed by iOS "Health" app. This can be used for surfacing data from other health app and read/write your own data. There are some basics we need to know to get started with the same;
- HKUnit - It represents a particular unit that can be accessed in any conversion (eg; Kg, Lb, Gram,..)
- HKQuantity - A double value related to a HKUnit. Note: there will be an excecption if you convert different units (e.g; Kg -> Liter), you can ask for compatibility (isCompatiableWithUnit:) if you are not sure
- HKObjectType - It represents different kind of data that we can store in HealthKit (e.g; Steps, Calories, BMI, Blood Pressure, etc..), it is a superclass for all Health Kit data types, i.e;
- HKCharactersticType - fixed user info like blood type, date of birth, gender
- HKSampleType - variable user info, it is consist of;
- HKQuantityType - (for Steps, Calories, etc.)
- HKCategoryType - used to categorize HKQuantityType, its paired with corresponding enum
- HKQuery - we can use predicates to search for our needs.
- HKObserverQuery - watches for changes in the database, it will called each and every something changed in database related to your query. It supports background delivery.
- HKAnchoredObjectQuery - it will help in paging of data, it is consist of Anchor and Limit. Anchor is a simple starting point. If we set Anchor to zero if will return all data with limit, for no limit we can use constant "HKObjectQueryNoLimit". Complition handler will have a new Anchor which we can use in our next query
We can use HKStatics to get required quantity data from the query output, we can ask statictics for all kinda data or a particular HKSource data. There are two kinda quantity data, i.e;
- Discrete - Min, Max, Average (e.g; user's average weight in a week)
- Cumulative - Sum (e.g; sum of steps taken in a perticular interval)
Good to know
- We need to activate HealthKit in your project settings
- We need to ask for authorization to read/write health data saparately for each and every type of info
- Always check of access authorization because user can manage anytime from outside the app
- An app can't get status for read access to the user info because of Apple's Privacy Policy
- We need to localize the units ourself, we can do so with the help of NSMassFormatter, NSLengthFormatter and NSEnergyFormatter
Post a Comment