Hi i want to display on my app dayly step count from healthKit
This is my code:
imports
import UIKit
import HealthKit
Class instance
var healthStore = HKHealthStore()
viewDidLoad method
override func viewDidLoad() {
super.viewDidLoad()
if HKHealthStore.isHealthDataAvailable(){
let writeDataTypes = dataTypesToWrite()
let readDataTypes = dataTypesToWrite()
healthStore.requestAuthorization(toShare: writeDataTypes as? Set<HKSampleType>, read: readDataTypes as? Set<HKObjectType>, completion: { (success, error) in
if(!success){
print("error")
return
}
self.updateSteps()
})
}
}
Write:
func dataTypesToWrite() -> NSSet{
let stepsCount = HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)
let returnSet = NSSet(objects: stepsCount!)
return returnSet
}
Read:
func dataTypesToRead() -> NSSet{
let stepsCount = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)
let returnSet = NSSet(objects: stepsCount!)
return returnSet
}
Now I want to create func updateSteps()
I have an answer to my question