swift ios 8.4中不允许授权共享以下类型:



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
    }

requestAuthorizationToShareTypes的参数是相反的。试试这个:

healthKitStore.requestAuthorizationToShareTypes(healthKitTypesToWrite, readTypes: healthKitTypesToRead, completion: { (success, error) -> Void in
    if( completion != nil )
    {
        completion(success:success,error:error)
    }
})

最新更新