0
Apple Healthアプリケーションから手順を読み込もうとしていますが、そのユーザーが許可または拒否を検出できません。ここに私のコードはあります: -HealthKitで読み取り手順の許可を確認する方法は?
NSArray *readTypes = @[[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]];
HKAuthorizationStatus permissionStatus = [self.healthStore authorizationStatusForType:[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]];
if (permissionStatus == HKAuthorizationStatusSharingAuthorized) {
return ;
}
else{
[self.healthStore requestAuthorizationToShareTypes:[NSSet setWithArray:@[]] readTypes:[NSSet setWithArray:readTypes] completion:^(BOOL success, NSError * _Nullable error) {
NSLog(@"%@",error);
[[NSNotificationCenter defaultCenter] postNotificationName:kConnectToAppleHealthNotification object:nil];
}];
}
ここでは、許可ステータスを確認しようとしているときに、ステップを読む許可を求める画面が表示されます。許可が拒否されたことを示します。許可を確認する方法は許可または拒否です。あなたは健康キットのデータをどうしたいあなたのコードを続行することができ、ここで
// Create the query
HKStatisticsCollectionQuery *query = [[HKStatisticsCollectionQuery alloc] initWithQuantityType:quantityType
quantitySamplePredicate:nil
options:HKStatisticsOptionCumulativeSum
anchorDate:anchorDate
intervalComponents:interval];
// Set the results handler
query.initialResultsHandler = ^(HKStatisticsCollectionQuery *query, HKStatisticsCollection *results, NSError *error) {
if (error) {
// Perform proper error handling here
NSLog(@"*** An error occurred while calculating the statistics: %@ ***",error.localizedDescription);
}
[results enumerateStatisticsFromDate:startDate
toDate:endDate
withBlock:^(HKStatistics *result, BOOL *stop) {
DLog(@" Result source %@ ",result.sources);
if(!result.sources){
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"You need to give us permission for getting your health data, Otherwise you can't get benefit of this app." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *actionYes = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: UIApplicationOpenSettingsURLString]];
}];
[alertController addAction:actionYes];
UIAlertAction *actionNo = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
delegate.window.userInteractionEnabled = NO;
}];
[alertController addAction:actionNo];
[delegate.window.rootViewController presentViewController:alertController animated:YES completion:nil];
return ;
}
:
http://stackoverflow.com/questions/33018445/how-to-check-if-healthkit-has-been-authorized – Balanced
[HealthKit認証ステータスは常に1]です(http://stackoverflow.com)。/question/29076655/healthkit-authorization-status-is-always-1) – Allan
あなたのアプリがHealthKitからデータを読み取る権限を持っているかどうかを確認する方法はありません。詳細は上記の答えを参照してください。 – Allan