【问题标题】:requestAuthorizationToShareTypes method not displaying Permissions prompt in iOS 8 Xcode 6requestAuthorizationToShareTypes 方法未在 iOS 8 Xcode 6 中显示权限提示
【发布时间】:2014-09-24 07:02:00
【问题描述】:
-(void)viewDidAppear:(BOOL)animated
{

[super viewDidAppear:animated];
if ([HKHealthStore isHealthDataAvailable]){
    NSSet *writeDataTypes = [self dataTypesToWrite];
    NSSet *readDataTypes = [self dataTypesToRead];

    [self.healthStore requestAuthorizationToShareTypes:writeDataTypes readTypes:readDataTypes completion:^(BOOL success, NSError *error) {

        NSLog(@"%s",__func__);
        if (!success) {
            NSLog(@"You didn't allow HealthKit to access these read/write data types. In your app, try to handle this error gracefully when a user decides not to provide access. The error was: %@. If you're using a simulator, try it on a device.", error);
            return;
        }

        dispatch_async(dispatch_get_main_queue(), ^{
            // Update the user interface based on the current user's health information.
            NSLog(@"=========================== %s",__func__);
        });
    }];
}


}

requestAuthorizationToShareTypes 不回调完成方法。

【问题讨论】:

  • 如果工作表从未出现并且从未调用完成,那么这听起来像是您应该提交的错误 (bugreporter.apple.com)。您是否尝试过查看设备的控制台输出以查看是否记录了任何错误?
  • 是的,我在控制台上什么都没试过。
  • 我遇到了同样的问题,所以我崩溃了:devforums.apple.com/thread/248835?tstart=0
  • 我得到一个控制台错误:__NSCFConstantString _allowAuthorizationForSharingWithEntitlements: 并跟踪:HKObjectType(HKAuthorization) _allowAuthorizationForSharing:types:entitlements:disallowedTypes, _throwIfAuthorizationDisallowedForSharing:types 和 requestAuthorizationToShareTypes:readTypes:shouldPrompt:completion
  • @marciokoko 当您应该传递 HKObjectType 时,您正在将 NSString 传递给 API。

标签: request ios8 xcode6 healthkit


【解决方案1】:

我遇到了类似的问题,权限框没有出现,也没有正确设置HKHealthStore,提前为我解决了这个问题

self.healthStore = [[HKHealthStore alloc] init];

【讨论】:

    【解决方案2】:

    这是一个示例实现,它返回类型而不是注释部分中描述的字符串。

    -(NSSet*)datatypesToWrite {
    
       NSArray *quantityTypes =
       @[HKQuantityTypeIdentifierHeartRate,
         HKQuantityTypeIdentifierBodyTemperature,
         HKQuantityTypeIdentifierBloodPressureSystolic,
         HKQuantityTypeIdentifierBloodPressureDiastolic,
         HKQuantityTypeIdentifierRespiratoryRate];
    
       NSMutableArray *hkTypes = [[NSMutableArray alloc] init];
    
       for (NSString *identifier in quantityTypes) {
         HKQuantityType *quantType =
          [HKObjectType quantityTypeForIdentifier:identifier];
         [hkTypes addObject:quantType];
       }
    
       // Make sure the types are of the correct style (Quantity, Category, Etc.)
       HKCategoryType *catType =
        [HKObjectType categoryTypeForIdentifier:HKCategoryTypeIdentifierSleepAnalysis];
       [hkTypes addObject:catType];
    
       return [[NSSet alloc] initWithArray:hkTypes];
    }
    

    每次您第一次请求新类型时,模式权限对话框都会显示(但如果您再次提示未授予的权限,它将不会再次显示)。 Apple 的指导方针是提示您可能需要的所有内容,但如果我知道有人只要求保存其中的几个,那么预先请求 12 种类型对我来说有点违反最佳实践。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-29
      • 1970-01-01
      • 1970-01-01
      • 2014-11-06
      • 1970-01-01
      • 2015-01-20
      • 1970-01-01
      相关资源
      最近更新 更多