【问题标题】:How to get meta data from iHealth using HealthKit?如何使用 HealthKit 从 iHealth 获取元数据?
【发布时间】:2014-12-10 14:12:47
【问题描述】:

问题

我们正在将 Healthkit 集成到我们现有的 iOS 应用中。我们已经设法从 Healthkit 中获取所有主要数据,例如跑步、体重等,但我们遇到的困难是在获取 元数据 时,比如用户记录该活动时,它是否会自动记录或者手动,数据的来源是什么等。

请看下图。这就是我们要获取的数据。

我们使用了 Objective-C

代码

- (void)updateUsers_BodyMassIndex
{

    // for getting body mass index.
    HKQuantityType *Distance_BodyMassIndex = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMassIndex];

    NSLog(@"%@",Distance_BodyMassIndex);

       // call query method for getting BodyMassIndex data
    [self.healthStore aapl_mostRecentQuantitySampleOfType:Distance_BodyMassIndex predicate:nil completion:^(HKQuantity *mostRecentQuantity, NSError *error)
    {
        if (!mostRecentQuantity)
        {
            NSLog(@"Either an error occured fetching the user's height information or none has been stored yet. In your app, try to handle this gracefully.");

            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"not available BodyMassIndex");
            });
        }
        else
        {
            // to get was user entered or not
            HKQuantityType *BodyMassIndexuserentered = [HKQuantityType quantityTypeForIdentifier:HKMetadataKeyWasUserEntered];
// getting unit for body mass index.
            HKUnit *DISTANCE_BodyMassIndexUnit = [HKUnit countUnit];
            double BodyMassIndex = [mostRecentQuantity doubleValueForUnit:DISTANCE_BodyMassIndexUnit];

            dispatch_async(dispatch_get_main_queue(), ^{

                NSLog(@"available body mass index %@",[NSNumberFormatter localizedStringFromNumber:@(BodyMassIndex) numberStyle:NSNumberFormatterNoStyle]);

            });
        }
    }];
}

图片

【问题讨论】:

    标签: objective-c ios8 healthkit


    【解决方案1】:

    这里是获取 wasUserEntered 键值的代码

    BOOL wasUserEntered = [[mostRecentQuantity.metadata objectForKey:HKMetadataKeyWasUserEntered] boolValue];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多