Skip to content

Instantly share code, notes, and snippets.

@leogdion
Last active June 11, 2018 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leogdion/8f691ba79d6da622bafac7f2ba85779d to your computer and use it in GitHub Desktop.
Save leogdion/8f691ba79d6da622bafac7f2ba85779d to your computer and use it in GitHub Desktop.
HealthKit – Apple Watch – Data and Authorization
if HKHealthStore.isHealthDataAvailable() {
let healthStore = HKHealthStore()
let heartRateQuantityType = HKObjectType.quantityType(forIdentifier: .heartRate)!
let allTypes = Set([HKObjectType.workoutType(), heartRateQuantityType ])
healthStore.requestAuthorization(toShare: nil, read: allTypes) { (result, error) in
if let error = error {
// deal with the error return
}
guard result else {
// deal with the failed request return
}
// begin any necessary work if needed
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment