objective-c - iOS8 在 iPad Air 上使用 HealthKit 时如何修复 "Health data is unavailable on this device"

标签 objective-c ipad ios8 healthkit

我正在尝试运行 WWDC 2014 中的“Fit”示例来检查 HealthKit。我使用的是更新至 iOS8 beta3 的 iPad Air。但是,当输入任何信息时,应用程序会崩溃并出现错误:

Error Domain=com.apple.healthkit Code=1 "Health data is unavailable on this device"

这是产生错误的方法的示例

    - (void)saveHeightIntoHealthStore:(double)height {
        // Save the user's height into HealthKit.
        HKUnit *inchUnit = [HKUnit inchUnit];
        HKQuantity *heightQuantity = [HKQuantity quantityWithUnit:inchUnit doubleValue:height];

        HKQuantityType *heightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight];
        NSDate *now = [NSDate date];

        HKQuantitySample *heightSample = [HKQuantitySample quantitySampleWithType:heightType quantity:heightQuantity startDate:now endDate:now];

        [self.healthStore saveObject:heightSample withCompletion:^(BOOL success, NSError *error) {
            if (!success) {

//Error reported here

                NSLog(@"An error occured saving the height sample %@. In your app, try to handle this gracefully. The error was: %@.", heightSample, error);
                abort();
            }
            [self updateUsersHeight];
        }];
    }

最佳答案

HealthKit 不适用于 iPad,仅适用于 iPhone 和 iPod - 就像 Passbook 一样。

关于objective-c - iOS8 在 iPad Air 上使用 HealthKit 时如何修复 "Health data is unavailable on this device",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24811242/

相关文章:

css - Twitter Bootstrap 和 iPad。 Div 没有包装内容

应用商店可以接受 iPhone 通过数据库更新 UI 内容吗?

ios - Segues 与 UIViewControllerAnimatedTransitioning

objective-c - CGEvent NSKeyDown 仅在应用程序位于最前面时才起作用?

ios - 激活任何 Typhoon 程序集时出错

ios - 可以流式传输超过 115kbps 的视频吗?

ios8 - 在键盘应用程序扩展中使用 UITextField

ios - UINavigationBar 的奇怪行为

具有自动布局的 iOS UIScrollView 未正确居中

ios - traitCollection.userInterfaceIdiom 返回 -1