Skip to content

Instantly share code, notes, and snippets.

@anka
Created January 4, 2015 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anka/ae78d389495b64d0fb80 to your computer and use it in GitHub Desktop.
Save anka/ae78d389495b64d0fb80 to your computer and use it in GitHub Desktop.
iOS update the current weight of the user
// Some weight in gram
double weightInGram = 83400.f;
// Create an instance of HKQuantityType and
// HKQuantity to specify the data type and value
// you want to update
NSDate *now = [NSDate date];
HKQuantityType *hkQuantityType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass];
HKQuantity *hkQuantity = [HKQuantity quantityWithUnit:[HKUnit gramUnit] doubleValue:weightInGram];
// Create the concrete sample
HKQuantitySample *weightSample = [HKQuantitySample quantitySampleWithType:hkQuantityType
quantity:hkQuantity
startDate:now
endDate:now];
// Update the weight in the health store
[healthStore saveObject:weightSample withCompletion:^(BOOL success, NSError *error) {
// ..
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment