In my application I am integrating health kit framework. My project requirement is I want to push body fat percentage and Lean body mass values from my application to Health kit application. So I am writing like this.
-(void)viewDidLoad
{
NSString *bodymassIndex=@"60";
double index=[bodymassIndex doubleValue];
[[GSHealthKitManager sharedManager]saveBodyMassIndexintoHealthstore:index];
// For Body Mass
NSString *bodymass=@"40";
double mass=[bodymass doubleValue];
[[GSHealthKitManager sharedManager]saveBodyMassintoHealthstore:mass];
}
- (void)saveBodyMassintoHealthstore:(double)width
{
HKUnit *massUnit = [HKUnit poundUnit];
HKQuantity * weightQuantity = [HKQuantity quantityWithUnit:massUnit doubleValue:width];
HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierLeanBodyMass];
NSDate *now = [NSDate date];
HKQuantitySample *weightsample = [HKQuantitySample quantitySampleWithType:weightType quantity:weightQuantity startDate:now endDate:now];
[self.healthStore saveObject:weightsample withCompletion:^(BOOL success, NSError *error){
if (!success){
NSLog(@"Error");
}
}];
}
- (void)saveBodyMassIndexintoHealthstore:(double)weight
{
HKUnit *massUnit = [HKUnit mileUnit];
HKQuantity * weightQuantity = [HKQuantity quantityWithUnit:massUnit doubleValue:weight];
HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMassIndex];
NSDate *now = [NSDate date];
HKQuantitySample *weightsample = [HKQuantitySample quantitySampleWithType:weightType quantity:weightQuantity startDate:now endDate:now];
[self.healthStore saveObject:weightsample withCompletion:^(BOOL success, NSError *error){
if (!success)
{
NSLog(@"Error");
}
}];
}
But my values are not showing in health kit application. So please guide me anybody. I can’t understand where is the issue exactly. Thanks in advance..