Upgrade to Pro — share decks privately, control downloads, hide ads and more …

iOS18とヘルスケアの睡眠対応

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

 iOS18とヘルスケアの睡眠対応

Avatar for Takuya Ohsawa

Takuya Ohsawa

November 27, 2024
Tweet

More Decks by Takuya Ohsawa

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ Takuya Osawa • גࣜձࣾasken ϞόΠϧςοΫϦʔυ • Swift΍Kotlin • ओͳ࢓ࣄ

    • iOS൛ ৯ࣄ؅ཧΞϓϦͷʮ͚͋͢Μʯͷ։ൃΛ୲౰ • झຯ • ໺ٿ؍ઓ
  2. import HealthKit let healthStore = HKHealthStore() do { try await

    healthStore .requestAuthorization( toShare: [], read: [HKCategoryType(.sleepAnalysis)] ) } catch { // Τϥʔॲཧ } ύʔϛογϣϯ
  3. import HealthKit // ೔෇ൣғͷϑΟϧλΛ࡞੒ let predicate = HKQuery.predicateForSamples(withStart: startDate, end:

    endDate, options: .strictStartDate) // αϯϓϧPredicateΛ࡞੒ let queryPredicate = HKSamplePredicate.sample(type: HKCategoryType(.sleepAnalysis), predicate: predicate) // ΫΤϦσΟεΫϦϓλΛ࡞੒ let descriptor = HKSampleQueryDescriptor( predicates: [queryPredicate], // ։࢝೔࣌ (startDate) Λঢॱ (ݹ͍ॱ) ʹฒ΂ସ͑ sortDescriptors: [SortDescriptor(\.startDate, order: .forward)], limit: HKObjectQueryNoLimit // શͯͷαϯϓϧΛऔಘ ) let healthStore = HKHealthStore() do { // ඇಉظͰσʔλΛऔಘ let samples: [HKSample] = try await descriptor.result(for: healthStore) } catch { // Τϥʔॲཧ } ਭ຾औಘ