3

不允许共享以下类型的授权: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
    }
4

1 回答 1

4

的论点requestAuthorizationToShareTypes是相反的。试试这个:

healthKitStore.requestAuthorizationToShareTypes(healthKitTypesToWrite, readTypes: healthKitTypesToRead, completion: { (success, error) -> Void in

    if( completion != nil )
    {
        completion(success:success,error:error)
    }
})
于 2015-08-12T21:35:41.773 回答