不允许共享以下类型的授权:swift ios版本8.4中的HKCharacteristicTypeIdentifierDateOfBirth,HKCharacteristicTypeIdentifierBiologicalSex
healthKitStore.requestAuthorizationToShareTypes(healthKitTypesToRead, readTypes: healthKitTypesToWrite, completion: { (success, error) -> Void in
if( completion != nil )
{
completion(success:success,error:error)
}
})
返回Fit希望写入HealthKit的数据类型。
func dataTypesToWrite() -> NSSet {
var dietaryCalorieEnergyType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDietaryEnergyConsumed) as HKQuantityType
var activeEnergyBurnType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned) as HKQuantityType
var heightType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeight) as HKQuantityType
var weightType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass) as HKQuantityType
var set = Set([dietaryCalorieEnergyType, activeEnergyBurnType, heightType, weightType])
return set//[NSSet setWithObjects:dietaryCalorieEnergyType, activeEnergyBurnType, heightType, weightType, nil];
}
返回Fit希望从HealthKit读取的数据类型。
func dataTypesToRead()->NSSet {
var dietaryCalorieEnergyType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDietaryEnergyConsumed) as HKQuantityType
var activeEnergyBurnType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned) as HKQuantityType
var heightType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeight) as HKQuantityType
var weightType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass) as HKQuantityType
var birthdayType = HKObjectType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierDateOfBirth) as HKCharacteristicType
var biologicalSexType = HKObjectType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierBiologicalSex) as HKCharacteristicType
var set = Set([dietaryCalorieEnergyType, activeEnergyBurnType, heightType, weightType, birthdayType, biologicalSexType])
return set
}
答案 0 :(得分:4)
requestAuthorizationToShareTypes
的论据被颠倒了。试试这个:
healthKitStore.requestAuthorizationToShareTypes(healthKitTypesToWrite, readTypes: healthKitTypesToRead, completion: { (success, error) -> Void in
if( completion != nil )
{
completion(success:success,error:error)
}
})