Skip to content

Health Kit ์•Œ์•„๋ณด๊ธฐ ๐Ÿ”Ž

Vardy edited this page Dec 10, 2023 · 1 revision

HealthKit Type

HKObjectType

HealthKit์˜ ๊ธฐ๋ณธ์ ์ธ ํƒ€์ž…. ์‹ฌ๋ฐ•์ˆ˜๋‚˜ ๊ฑธ์Œ์ˆ˜, ์ˆ˜๋ฉด ๋ถ„์„ ๋“ฑ์˜ ์—ฌ๋Ÿฌ ๋ฐ์ดํ„ฐ ํƒ€์ž…์ด ์ด ํƒ€์ž…์„ ์ƒ์†๋ฐ›์Šต๋‹ˆ๋‹ค.

์ตœ์ƒ์œ„ ํƒ€์ž…์ด๋‹ค๋ณด๋‹ˆ ๋ณ„ ๊ธฐ๋Šฅ์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ €๋Š” ๋‹จ์ˆœํžˆ NSObject๊ฐ™์€ ๋…€์„์ด๊ตฌ๋‚˜ ๋ผ๊ณ  ์ดํ•ดํ–ˆ์Šต๋‹ˆ๋‹ค.

Untitled

HKSampleType

HKObjectType์˜ ์ถ”์ƒ ์„œ๋ธŒํด๋ž˜์Šค(abstract subclass)์ž…๋‹ˆ๋‹ค. data sample์„ ํ‘œํ˜„ํ•˜๋Š” ๋…€์„์ด๋ฉฐ, ์ถ”์ƒ ํด๋ž˜์Šค๋กœ ๋งŒ๋“ค์–ด์กŒ๋‹ค๋ณด๋‹ˆ ์ง์ ‘ ์ด๋‹ˆ์…œ๋ผ์ด์ €๋กœ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ์„ ํ”ผํ•˜๋ผ๊ณ  ์ง€์‹œํ•ฉ๋‹ˆ๋‹ค.

HKSampleType์„ ์ƒ์†๋ฐ›์€ concrete type์œผ๋กœ๋Š”HKCategoryType, HKCorrelationType, HKQuantityType, HKWorkoutType๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

HKQuantityType

์‹ฌ๋ฐ•์ˆ˜, ๊ฑท๊ฑฐ๋‚˜ ๋›ด ๊ฑฐ๋ฆฌ, ์‚ฌ์ดํด๋ง ๊ฑฐ๋ฆฌ, ์ฒด์ค‘, ์†Œ๋ชจํ•œ ์นผ๋กœ๋ฆฌ ๋“ฑ๊ณผ ๊ฐ™์ด **์ˆ˜๋Ÿ‰ ๋ฐ์ดํ„ฐ(QuantityType)**์„ ๋‚˜ํƒ€๋‚ด๋Š” ๋ฐ ์‚ฌ์šฉํ•˜๋Š” ํƒ€์ž…์ž…๋‹ˆ๋‹ค.

let distanceType = HKQuantityType(.distanceWalkingRunning)
let caloriesType = HKQuantityType(.activeEnergyBurned)

HealthKit Query


์‚ฌ์šฉ๋ฒ•

healthStore?.requestAuthorization(toShare: [HKQuantityType(.distanceWalkingRunning)], read: nil) { success, error in
  // ์—ฌ๊ธฐ์„œ success๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ๋ฐ์ดํ„ฐ ํƒ€์ž… ์„ค์ • ๊ถŒํ•œ์„ ํ—ˆ์šฉํ–ˆ๋‹ค๋Š” ๋œป์ด ์•„๋‹ˆ๋ผ, ๋‹จ์ˆœํžˆ ์ธ๊ฐ€ ์š”์ฒญ์— ์„ฑ๊ณตํ–ˆ๋‹ค๋Š” ๋œป์ž…๋‹ˆ๋‹ค.
  if success {

  } else {
    // ๋งŒ์•ฝ ์‹คํŒจํ–ˆ๋‹ค๋ฉด ๋‹ค์‹œ ์‹œ๋„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  }
}

Creating a workout route | Apple Developer Documentation

HKWorkoutRouteQuery | Apple Developer Documentation

Building a multidevice workout app | Apple Developer Documentation

Getting started with HealthKit - WWDC20 - Videos - Apple Developer

Authorizing access to health data | Apple Developer Documentation

Creating a Mobility Health App | Apple Developer Documentation

Clone this wiki locally