5

我在我的应用程序中使用AppleHealthKit。一切正常。问题是我无法检测到用户在请求许可时是否点击了“不允许”按钮。

在此处输入图像描述

使用这种方法,我的应用程序使用HealthKit,即使用户不允许这样做。

requestAuthorizationToShareTypes(healthKitTypesToWrite, readTypes: healthKitTypesToRead) { (success, error) -> Void in
        if( completion != nil ) {
            completion(success:success,error:error)
        }

苹果文档:

在此处输入图像描述

所以基本上我的问题是如何检测到这个?

4

2 回答 2

7

根据设计,您无法检测到它:

为帮助防止敏感健康信息可能泄露,您的应用无法确定用户是否已授予读取数据的权限。如果您没有获得许可,它只会显示为在 HealthKit 存储中没有请求类型的数据。

(来自香港健康商店

于 2016-08-06T09:13:56.663 回答
4

您可以这样做,但仅适用于一种特定类型并且仅适用于写入数据(如果您必须检查它们,您也可以对其他类型执行相同操作)

HKHealthStore *_healthStore;
HKQuantityType *stepsType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];

HKAuthorizationStatus status = [_healthStore authorizationStatusForType:stepsType];

BOOL isActive;
switch (status) {
    case HKAuthorizationStatusSharingAuthorized:
        isActive = YES;
        break;
    case HKAuthorizationStatusSharingDenied:
        isActive = NO;
        break;
    case HKAuthorizationStatusNotDetermined:
        isActive = NO;
        break;

    default:
        break;
}

NSLog(@"STATUS-------%@", isActive ? @"yes" : @"no");
于 2017-06-08T12:28:28.417 回答