double
값을 반환하려고하지만 원하는 값을 반환하지 않습니다. 다른 대안을 시도했지만 정확한 값을 반환 할 수 없었습니다. 여기에 도달하려고하는 방법을 알 수 있습니다.블록에서 값을 반환하는 방법
- (double)readData
{
__block double usersWeight;
HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass];
[self.healthStore aapl_mostRecentQuantitySampleOfType:weightType predicate:nil completion:^(HKQuantity *mostRecentQuantity, NSError *error) {
if (!mostRecentQuantity) {
NSLog(@"%@",error);
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Not Available");
});
}
else {
// Determine the weight in the required unit.
HKUnit *weightUnit;
if([strWeightUnit isEqualToString:@"kgs"])
{
weightUnit = [HKUnit gramUnit];
usersWeight = [mostRecentQuantity doubleValueForUnit:weightUnit];
usersWeight = usersWeight/1000.0f; //kg value
}
else
{
weightUnit = [HKUnit poundUnit];
usersWeight = [mostRecentQuantity doubleValueForUnit:weightUnit];
}
}
}];
return usersWeight;
}
원래 방법에 대한 완료 블록을 사용한 다음 원하는 값으로 블록을 다시 호출 할 수 있습니다. – holex