【发布时间】:2016-05-12 09:39:17
【问题描述】:
我已将 HealthKit 框架集成到我的应用程序中。 HealthKit 仅从应用程序启动一次。以下代码位于为 HealthKit 创建的单例类中。
func requestAuthorization()
{
if (HKHealthStore .isHealthDataAvailable() == false)
{
return
}
let healthKitTypesToRead : Set = [
HKObjectType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierFitzpatrickSkinType)!,
HKObjectType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierBiologicalSex)!,
HKObjectType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierBloodType)!
]
let healthKitTypesToWrite : Set = [
HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyFatPercentage)!,
HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMassIndex)!,
HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeight)!,
HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass)!,
HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierLeanBodyMass)!
]
self.healthStore.requestAuthorizationToShareTypes(healthKitTypesToWrite, readTypes: healthKitTypesToRead) {
(success, error) -> Void in
if !success{
print("error")
}
}
}
requestAuthorization 方法正在调用视图控制器的按钮操作,
@IBAction func healthIntegrationButton(sender: UIButton)
{
HealthKitHandler.shared.requestAuthorization()
}
一旦我关闭了 healthkit 应用程序,按钮操作就不会发生任何操作。再次,如果我从模拟器中删除应用程序并单击按钮 healthkit 应用程序将启动。
谁能帮助我们上面的代码有什么问题。提前致谢。
【问题讨论】:
标签: ios iphone swift healthkit