必须在应用程序的Info.plist中设置NSHealthShareUsageDescription才能请求读取授权

问题描述 投票:7回答:1

我有一个使用的框架

_healthStore requestAuthorizationToShareTypes:writeTypes readTypes:readTypes completion:^(BOOL success, NSError *error) {

当我将框架包含到我的iOS应用程序中并将以下内容放入我的应用程序info.plist文件中时

<key>NSHealthShareUsageDescription</key>
<string>Read heart rate monitor data.</string>
<key>NSHealthUpdateUsageDescription</key>
<string>Share workout data with other apps.</string>

一切正常 - 不包括那些键会导致以下错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSHealthShareUsageDescription must be set in the app's Info.plist in order to request read authorization.'

我的问题是,当运行框架的单元测试时,它会因上述错误而崩溃。我把密钥放在框架和测试目标的所有info.plist文件中,但仍然会崩溃。

应该使用哪个plist文件来运行测试目标?

(还应该提到我正在切换到Swift 3 - 这是Objective-C项目的一部分 - 在iOS 10和XCode 8之前,这一切都运行良好)。

我已经用适当的单元测试创​​建了一个框架来显示问题:https://github.com/asensei/HKHealthStoreFrameworkUnitTestBug

objective-c ios10 xcode8
1个回答
4
投票

您必须将NSHealthShareUsageDescription和NSHealthUpdateUsageDescription键添加到应用程序中的Info.plist文件中。你这样做:

  1. 单击“Info.plist”文件
  2. 右键单击屏幕并选择添加行。
  3. 滚动到“隐私 - 健康共享......”和“隐私 - 健康更新......”
  4. 选择这两个,你应该是好的。
© www.soinside.com 2019 - 2024. All rights reserved.