无法在Xcode中启用Health Records功能

时间:2018-09-13 11:41:18

标签: ios xcode health-kit

我正在按照official manual的说明设置HealthKit以读取用户的健康记录。我启用了它,并通过了所有三个步骤来使其起作用,但是以某种方式禁用了“运行状况记录”功能,因此我无法对其进行检查。结果,该应用崩溃,因为它无法验证对健康记录的请求。

如何启用它?

具有iOS 12 SDK的Xcode版本10.0 beta 6(10L232m)。

enter image description here

还有一个授权文件:

enter image description here

帐户设置:

enter image description here

我的代码:

RCT_EXPORT_METHOD(requestAccess:(RCTResponseSenderBlock)callback) {
  NSNull * null = [NSNull null];

  NSSet * recordTypes = [self recordTypes];

  HKHealthStore *store = [HKHealthStore new];
  [store requestAuthorizationToShareTypes:nil
                                readTypes:recordTypes
                               completion:^void (BOOL success, NSError * _Nullable error) {

    if (success) {
      callback(@[null, @true]);

崩溃报告

Exception 'Authorization to read the following types is disallowed: HKClinicalTypeIdentifierMedicationRecord' was thrown while invoking requestAccess on target AppHealthRecords with params (
    259
)
callstack: (
    0   CoreFoundation                      0x000000010709429b __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x0000000105777735 objc_exception_throw + 48
    2   CoreFoundation                      0x00000001070940f5 +[NSException raise:format:] + 197
    3   HealthKit                           0x0000000104dc7ec0 -[HKHealthStore _throwIfAuthorizationDisallowedForSharing:types:] + 540
    4   HealthKit                           0x0000000104dc6912 -[HKHealthStore _validateAuthorizationRequestWithShareTypes:readTypes:] + 224
    5   HealthKit                           0x0000000104dc6a82 -[HKHealthStore requestAuthorizationToShareTypes:readTypes:shouldPrompt:completion:] + 321
    6   HealthKit                           0x0000000104dc680f -[HKHealthStore requestAuthorizationToShareTypes:readTypes:completion:] + 77
    7   app                                 0x0000000104574c43 -[AppHealthRecords requestAccess:] + 307
    8   CoreFoundation                      0x000000010709b11c __invoking___ + 140
    9   CoreFoundation                      0x00000001070985b5 -[NSInvocation invoke] + 325
    10  CoreFoundation                      0x0000000107098a06 -[NSInvocation invokeWithTarget:] + 54
    11  app                                 0x000000010461ec6a -[RCTModuleMethod invokeWithBridge:module:arguments:] + 2810
    12  app                                 0x00000001046d5dd6 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 790
    13  app                                 0x00000001046d58ef _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 127
    14  app                                 0x00000001046d5869 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 25
    15  libdispatch.dylib                   0x00000001099c251d _dispatch_call_block_and_release + 12
    16  libdispatch.dylib                   0x00000001099c3587 _dispatch_client_callout + 8
    17  libdispatch.dylib                   0x00000001099ca058 _dispatch_lane_serial_drain + 720
    18  libdispatch.dylib                   0x00000001099cab9b _dispatch_lane_invoke + 401
    19  libdispatch.dylib                   0x00000001099d39c6 _dispatch_workloop_worker_thread + 645
    20  libsystem_pthread.dylib             0x0000000109d48fd2 _pthread_wqthread + 980
    21  libsystem_pthread.dylib             0x0000000109d48be9 start_wqthread + 13
)

2 个答案:

答案 0 :(得分:0)

您需要将Health Records键添加到您的权利文件中。

并确保在NSHealthClinicalHealthRecordsShareUsageDescription中为Info.plist键添加一个条目

权利屏幕截图:
Entitlements screenshot

答案 1 :(得分:0)

您需要为您的项目附加一个开发者帐户,以便能够打开Health Records