我有一个通用的iOS应用程序,它引用HealthKit。当应用程序安装在iPhone上时,应用程序使用HKHealthStore检索健康数据,当应用安装在iPad上时,我通过检查HKHealthStore.isHealthDataAvailable是否为false来跳过HealthKit查询。这一切都很好,但为了让应用程序在iPad上运行,我必须从我的应用程序的.plist中删除“必需设备功能”下的"healthkit“条目。这很有道理,因为iPad上没有healthkit,所以要求它安装它,这样应用程序就不会在iPad上安装。所有这些都已经在我提交给应用商店的应用程序中完成,并且已经获得批准。
现在我正在做一个应用程序更新,我想显示用户在Health中手动调整的单元首选项。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“entery,那么这个错误就消失了,我得到了想要的结果。但是这对我来说不是一个解决方案,因为这样我就不能在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>发布于 2015-09-30 20:30:10
我发现这里发生了什么。在HKHealthStore请求访问健康类型和请求首选单元之间存在线程问题。我不知道为什么.plist条目修复了这个问题..。但是,将首选单元请求移到HKHealthStore请求访问方法的完成块中,就解决了这个问题。
https://stackoverflow.com/questions/32825730
复制相似问题