【发布时间】:2015-09-28 14:39:09
【问题描述】:
我有一个引用 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>
【问题讨论】:
-
对不起,我的第一个答案是基于错误地阅读了您的问题。您从“必需的设备功能”中删除“healthkit”的具体步骤是什么?
-
我进入了我的应用程序的 .plist 文件,并在
UIRequiredDeviceCapabilities 部分下删除了healthkit 条目。这是我发现引用 HealthKit 的应用程序实际上可以安装在 iPad 上的唯一方法(即使 iPad 代码不使用 HealthKit)。 -
听起来是对的。您应用的 .entitlements 文件的内容是什么?
-
我已经更新了我上面的帖子,以显示权利文件包含的内容。这有点像 Apple 的错误,当调用该方法时,他们在 .plist 中查找,而不是在权利文件中查找。
-
也许可以尝试向 Apple 提交一个但是,并附上重现该问题的项目副本。
标签: ios healthkit hkhealthstore