Created
September 17, 2014 21:34
-
-
Save jault3/81b1a739768cdf430a29 to your computer and use it in GitHub Desktop.
Save Weight to HealthKit
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
double weight = _txtWeight.text.doubleValue; | |
HKUnit *poundUnit = [HKUnit poundUnit]; | |
HKQuantity *weightQuantity = [HKQuantity quantityWithUnit:poundUnit doubleValue:weight]; | |
HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass]; | |
NSDate *now = [NSDate date]; | |
HKQuantitySample *weightSample = [HKQuantitySample quantitySampleWithType:weightType quantity:weightQuantity startDate:now endDate:now]; | |
[self.healthStore saveObject:weightSample withCompletion:^(BOOL success, NSError *error) { | |
[self retrieveWeight]; | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment