2

我有一个引用 HealthKit 的通用 iOS 应用程序。当应用程序安装在 iPhone 上时,应用程序使用 HKHealthStore 来检索健康数据,当它在 iPad 上时,我通过检查 HKHealthStore.isHealthDataAvailable 是否为假来跳过 HealthKit 查询。这一切都很好,但为了让应用程序在 iPad 上运行,我必须从我的应用程序的 .plist 中的“所需设备功能”下删除“healthkit”条目。这是有道理的,因为 iPad 上没有 healthkit,所以需要它,所以应用程序不会安装在 iPad 上。所有这些都已经在我提交到应用商店并获得批准的应用中完成。

现在我正在更新应用程序,我想显示用户可能在 Health App 中手动调整的单位偏好。HKHeathStore 的文档说您可以使用preferredUnitsForQuantityTypes方法执行此操作。但是,从我的 iPhone 应用程序调用此方法会给我以下错误:

Error Domain=com.apple.healthkit Code=4 "Missing com.apple.developer.healthkit entitlement." UserInfo={NSLocalizedDescription=Missing com.apple.developer.healthkit entitlement.}

除了我的应用程序 ID 中已经有 healthkit 权利。如果我在 .plist 的“必需的设备功能”部分下添加“healthkit”条目,那么这个错误就会消失,我会得到想要的结果。但这对我来说不是解决方案,因为那时我无法在 iPad 上安装该应用程序。

我的问题是,我如何支持 iPhone 版本可以成功调用 HKHealthStore.preferredUnitsForQuantityTypes 的通用应用程序?

编辑这是我的 .entitlements 文件的样子:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.developer.healthkit</key>
    <true/>
    <key>com.apple.security.application-groups</key>
    <array>
        <string>group.com.mycompany.myapp</string>
    </array>
</dict>
</plist>
4

1 回答 1

0

我发现这里发生了什么。在 HKHealthStore 请求访问健康类型和请求首选单元之间存在线程问题。我不确定为什么 .plist 条目修复了这个问题......但是将首选单位请求移动到 HKHealthStore 的请求访问方法的完成块中解决了这个问题。

于 2015-09-30T20:30:10.423 回答