7

We're making an app which collects a special type of data not supported by the list in the Health app. Is there a way to create a new category for this?

2 Answers 2

12

No, there isn't at this time. From the HealthKit Framework Reference:

The HealthKit framework is designed to share data between apps in a meaningful way. To that end, the framework constrains the types of data and units to a predefined list. These limits ensure that other apps understand both what the data means and how it can be used. As a result, developers cannot create custom data types or units. Instead, HealthKit attempts to provide a reasonably complete list of data types and units.

If I were you, I would file a Radar (http://bugreport.apple.com) detailing the type of health data you'd like to see added.

2
  • Is this still valid? I can't find it on the page you linked to anymore. Sep 19, 2018 at 13:11
  • 1
    @pkyeck See developer.apple.com/documentation/healthkit/… (looks like they moved it): "The quantity’s units must correspond to the allowable units described in the type identifier’s documentation."
    – Undo
    Sep 19, 2018 at 14:04
7

Yes, you can. Just define it as an NSDictionary and pass it into the metadata field. Note the custom fields below: push_ups, sit_ups, and status.

let end = NSDate()
let start = NSCalendar.currentCalendar().dateByAddingUnit(.CalendarUnitMinute,
    value: -2, toDate: end, options: nil)

let energyBurned = HKQuantity(unit: HKUnit.kilocalorieUnit(),
    doubleValue: 425.0)

let distance = HKQuantity(unit: HKUnit.mileUnit(),
    doubleValue: 0)

let status = "felt okay...could have done more"
let push_ups = 40
let sit_ups = 50

let s = ["push_ups": push_ups,
    "sit_ups": sit_ups,
    "notes": status
    ] as NSDictionary

// Provide summary information when creating the workout.
let wrkOut = HKWorkout(activityType: HKWorkoutActivityType.FunctionalStrengthTraining,
    startDate: start, endDate: end, duration: 0,
    totalEnergyBurned: energyBurned, totalDistance: distance, metadata: s as! [NSObject : AnyObject])
2
  • 1
    It's technically metadata - unlike other observation collection systems (with different extension mechanisms) metadata is not designed to store Codeable values. This may or may not matter. Mar 4, 2016 at 0:51
  • 2
    So using this method is it also possible to store the data in the HealthStore and have it display in the apple Health app as a custom HKUnit on the graph?
    – Edison
    Aug 12, 2016 at 2:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.