WWDC 2015

What's new in HealthKit

New Unit Perference

User can now change the units of related data types like weight and height in iOS 8.2.

use preferredUnitsForQuantityTypes of HKHealthStore to set preferred unit type.

use HKUserPreferencesDidChangeNotification as notification key to monitor if there are any changes.

New data type in iOS 9

  • Watch intake
  • UV exposure with Fitzpatrick skin type
  • Basal Body Temp.
  • Cervical Mucus Quality
  • Ovulation Test Result (+ve/-ve)
  • Menstruation with metadata
  • Vaginal Spotting
  • Sexual Activity

Change of HKObject

  • source of HKObject had been removed.

  • Added sourceRevision for storing sourceRevision and source with that object

  • Added new device property for storing related health devices information. use class function localDevice() for getting the current device's information.

New predicate for query

HKQuery is added for querying HealthKit databases

Deletion of HKObject

deleteObjects is added for deleting multiple HKObject

deleteObjectsOfType(objectType:predicate:completion) for deleting objects fits the predicate

Querying deleted object

No easy way for tracking deleted object in iOS 8

HKAnchoredObjectQuery for query all sample with predicate provided. The result also includes delete objects for developers to sync their app databases.

Background delivery invoke enableBackgroundDeliveryForType of HKHealthStore for sending info to third parties app.

Updating

use updateHandler of HKAnchoredObjectQuery to be informed whenever there are updates.

HealthKit in WatchOS

  • Same API
  • Assess to activity and workout data
  • New workout api
  • data syncs to companion device

Steps:

  1. Request authorization for workout data types (like walking and running)
  2. Start the HKWorkoutSession
  3. Retrieve streamed samples from HKAnchoredObjectQuery
  4. Save the HKWorkout and related sample