当第一次使用我想要的权限集调用requestAuthorizationToShareTypes:readTypes:completion:
时,我可以看到这个模式视图请求用户授权以读取和共享应用程序可能需要访问的每种类型的对象。HKHealthStore
HKQuantityType
我试图弄清楚是否有办法提示用户这个模态视图,除了我第一次打电话:requestAuthorizationToShareTypes:readTypes:completion:
。
我尝试requestAuthorizationToShareTypes:readTypes:completion:
使用相同的集合每次调用,但在第一次调用后它不再提示。在尝试使用不存在的新类型更改集合时,我可以成功提示此屏幕,但我不认为每次使用集合中的新类型调用此方法都是HKQuantityType
正确的方法(因为有一个限制类型的数量存在)。
甚至可能吗?
感谢您提供任何帮助。
更新
我将添加一些调用代码片段:
[self.healthStore requestAuthorizationToShareTypes:writeDataTypes readTypes:readDataTypes completion:^(BOOL success, NSError *error) {
if (!success) {
NSLog(@"You didn't allow HealthKit to access these read/write data types. The error was: %@.", error);
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
// Update the user interface based on the current user's health information.
});
}];
writeDataTypesz
和从以下方法返回readDataTypes
:NSSet
// Returns the types of data that I want to write to HealthKit.
- (NSSet *)dataTypesToWrite
{
HKQuantityType *heightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight];
HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass];
return [NSSet setWithObjects: heightType, weightType, nil];
}
// Returns the types of data that I want to read from HealthKit.
- (NSSet *)dataTypesToRead
{
HKQuantityType *heightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight];
HKQuantityType *weightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass];
HKCharacteristicType *birthdayType = [HKCharacteristicType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierDateOfBirth];
HKCharacteristicType *biologicalSex = [HKCharacteristicType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierBiologicalSex];
return [NSSet setWithObjects:heightType,weightType,birthdayType,biologicalSex, nil];
}
每次调用时将集合更改为包含新requestAuthorizationToShareTypes:readTypes:completion:
类型会导致打开此视图,其中包含我曾经请求权限的所有类型(不一定在此特定调用中):