-
-
Save anka/ae78d389495b64d0fb80 to your computer and use it in GitHub Desktop.
iOS update the current weight of the user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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