18

特定の種類の情報を読み取るために HealthKit を使用しています。特に書き込み機能を求めているわけではありません。ユーザーが特定のヘルスタイプの読み取りを許可しているかどうかを検出しようとすると、問題が発生します。

これを行うための意図された方法は、HKHealthStore の authorizationStatusForType メソッドを使用することだと思いますが、これは拒否または不明のみが返されます。書き込みタイプの許可のみを返します。この方法を使用して読み取りまたは別の回避策を見つけた人はいますか?

HKQuantityType *stepsType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight];
HKAuthorizationStatus status = [self.healthStore authorizationStatusForType:stepsType];
4

2 に答える 2

21

プライバシー上の理由から、特定の種類のアプリケーションの読み取り承認ステータスを表示することはできません。

于 2014-08-27T06:10:09.177 に答える
1
        NSArray *quantityTypesUsedInApp = @[HKQuantityTypeIdentifierBodyMass,
                                             HKQuantityTypeIdentifierHeight,
                                             HKQuantityTypeIdentifierBodyMassIndex,
                                             HKQuantityTypeIdentifierBodyFatPercentage,
                                             HKQuantityTypeIdentifierLeanBodyMass];

    for (NSString *identifier in quantityTypesUsedInApp) {

        HKQuantityType *sampleType = [HKQuantityType quantityTypeForIdentifier:identifier];
        NSSet *requestSampleUnit = [NSSet setWithObject:sampleType];

        [self.healthKitStore preferredUnitsForQuantityTypes:requestSampleUnit completion:^(NSDictionary *preferredUnits, NSError *error) {

            if (!error) {

                HKUnit *unit = [preferredUnits objectForKey:sampleType];
                NSLog(@"%@ : %@", sampleType.identifier, unit.unitString);
                //sampleType enabled for read

            } else {

                switch (error.code) {
                    case 5:

                        NSLog(@"%@ access denied", sampleType.identifier);
                       //sampleType denied for read
                        break;

                    default:
                        NSLog(@"request preffered quantity types error: %@", error);
                        break;
                }


            }

        }];

    }
于 2015-08-25T21:14:23.137 に答える