Can I add custom data to HealthKit?
No, not at this time. From the HealthKit Framework Reference :
The HealthKit framework is for sharing data between apps. For this purpose, the structure contains data types and units in a predefined list. These restrictions ensure that other applications understand what the data means and how it can be used. As a result, developers cannot create their own data types or units . Instead, HealthKit tries to provide a fairly comprehensive list of data types and units.
If I were you, I would put a radar ( http://bugreport.apple.com ) that details the type of health data that you would like to see.
source to share
Yes, you can. Just define it as NSDictionary
and go to 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])
source to share