iamjustaprogrammer
iamjustaprogrammer

Reputation: 1654

Is it possible to add custom data to HealthKit?

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?

Upvotes: 7

Views: 7198

Answers (2)

Mike Chirico
Mike Chirico

Reputation: 3491

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])

Upvotes: 7

Undo
Undo

Reputation: 25687

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.

Upvotes: 12

Related Questions