EddyVerbruggen / HealthKit

Cordova plugin for the iOS HealthKit framework
MIT License
167 stars 214 forks source link

Saving HKCategory to HK #88

Open manuelnaturalcycles opened 7 years ago

manuelnaturalcycles commented 7 years ago
window.plugins.healthkit.saveQuantitySample(
  {
    startDate: date, // point in time means that endDate = startDate
    endDate: date, // now
    sampleType: 'HKCategoryTypeIdentifierSexualActivity',
    amount: '0',
    unit: 'count',
    metadata: {
      HKSexualActivityProtectionUsed: protectionUsed
    }
  }, function (r) {
    $log.debug('Wrote data to HK with sex for date: ' + date)
  }, function (e) {
    alert('error: ' + e)
    $log.error(e)
  }
);

I cant save Sexual Activity because it asks for a unit. How should I handle saving data which is not really a quantity sample but a Category?

EddyVerbruggen commented 7 years ago

Looks like the plugin needs to be altered a bit for this type of usage. Apple doc.

manuelnaturalcycles commented 7 years ago

I see.

I have an old version of the plugin forked from this one which actually had a saveCategorySample method implemented.

Was this removed for any specific reason?

I will work on this modification to see if i can make it happen.

thanks!

EddyVerbruggen commented 7 years ago

Perhaps it was removed by a PR, not intentionally IIRC.

manuelnaturalcycles commented 7 years ago

Oj! That seems unfortunate, it was a cool feature.

manuelnaturalcycles commented 7 years ago

Hej @EddyVerbruggen I successfully readded the functionality in this fork https://github.com/manuelnaturalcycles/HealthKit I am a bit lost as to how to structure the code that I added so that you would even consider merging it into real branch, is there any guide i should use?

EddyVerbruggen commented 7 years ago

Hi @manuelnaturalcycles your code looks good. I may need to tweak a little thingy after merging but that's not an issue.

Do you have a JS sample I can test this method with perhaps?