getting the most out of healthkit - apple developer€¦ · health records represent different...
TRANSCRIPT
![Page 1: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/1.jpg)
© 2016 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.
What’s new and best practices
App Frameworks #WWDC16
Session 209
Getting the Most Out of HealthKit
Matthew Salesi iOS Software EngineerJoefrey Kibuule iOS Software Engineer
![Page 2: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/2.jpg)
![Page 3: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/3.jpg)
Authorization
![Page 4: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/4.jpg)
Authorization
Activity Rings
![Page 5: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/5.jpg)
Authorization
Activity Rings
Health Records
![Page 6: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/6.jpg)
Authorization
Activity Rings
Health Records
Handling Data
![Page 7: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/7.jpg)
Authorization
![Page 8: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/8.jpg)
OverviewAuthorization
![Page 9: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/9.jpg)
OverviewAuthorization
Users are in control
![Page 10: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/10.jpg)
OverviewAuthorization
Users are in controliOS mediates authorization requests
![Page 11: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/11.jpg)
OverviewAuthorization
Users are in controliOS mediates authorization requestsPermissions may change at any time
![Page 12: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/12.jpg)
OverviewAuthorization
Users are in controliOS mediates authorization requestsPermissions may change at any timeRead and write authorization are independent
![Page 13: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/13.jpg)
Read/write permissionsAuthorization
Permissions Can Query? Can Save?
Read + Write Yes Yes
Read Yes No
Write Own data only Yes
None No No
![Page 14: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/14.jpg)
Read/write permissionsAuthorization
Permissions Can Query? Can Save?
Read + Write Yes Yes
Read Yes No
Write Own data only Yes
None No No
![Page 15: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/15.jpg)
Read/write permissionsAuthorization
Permissions Can Query? Can Save?
Read + Write Yes Yes
Read Yes No
Write Own data only Yes
None No No
![Page 16: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/16.jpg)
Read/write permissionsAuthorization
Permissions Can Query? Can Save?
Read + Write Yes Yes
Read Yes No
Write Own Data Only Yes
None No No
![Page 17: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/17.jpg)
Read/write permissionsAuthorization
Permissions Can Query? Can Save?
Read + Write Yes Yes
Read Yes No
Write Own Data Only Yes
None No No
![Page 18: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/18.jpg)
Usage descriptionsAuthorization NEW
![Page 19: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/19.jpg)
Usage descriptionsAuthorization
Apps must explain how they will use Health data
NEW
![Page 20: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/20.jpg)
Usage descriptionsAuthorization
Apps must explain how they will use Health dataStatically declared in Info.plist
NEW
![Page 21: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/21.jpg)
Usage descriptionsAuthorization
Apps must explain how they will use Health dataStatically declared in Info.plist• NSHealthShareUsageDescription
NEW
![Page 22: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/22.jpg)
Usage descriptionsAuthorization
Apps must explain how they will use Health dataStatically declared in Info.plist• NSHealthShareUsageDescription• NSHealthUpdateUsageDescription
NEW
![Page 23: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/23.jpg)
// Requesting Authorization
import HealthKit
guard HKHealthStore.isHealthDataAvailable() else { return }
let healthStore = HKHealthStore()
let shareableTypes = Set([ ... ])
let readableTypes = Set([ ... ])
// Presents authorization sheet to user the first time this is called.
healthStore.requestAuthorization(toShare: shareableTypes,
read: readableTypes) { success, error in
// Handle authorization response here.
}
![Page 24: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/24.jpg)
// Requesting Authorization
import HealthKit
guard HKHealthStore.isHealthDataAvailable() else { return }
let healthStore = HKHealthStore()
let shareableTypes = Set([ ... ])
let readableTypes = Set([ ... ])
// Presents authorization sheet to user the first time this is called.
healthStore.requestAuthorization(toShare: shareableTypes,
read: readableTypes) { success, error in
// Handle authorization response here.
}
![Page 25: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/25.jpg)
// Requesting Authorization
import HealthKit
guard HKHealthStore.isHealthDataAvailable() else { return }
let healthStore = HKHealthStore()
let shareableTypes = Set([ ... ])
let readableTypes = Set([ ... ])
// Presents authorization sheet to user the first time this is called.
healthStore.requestAuthorization(toShare: shareableTypes,
read: readableTypes) { success, error in
// Handle authorization response here.
}
![Page 26: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/26.jpg)
// Requesting Authorization
import HealthKit
guard HKHealthStore.isHealthDataAvailable() else { return }
let healthStore = HKHealthStore()
let shareableTypes = Set([ ... ])
let readableTypes = Set([ ... ])
// Presents authorization sheet to user the first time this is called.
healthStore.requestAuthorization(toShare: shareableTypes,
read: readableTypes) { success, error in
// Handle authorization response here.
}
![Page 27: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/27.jpg)
watchOSAuthorization
![Page 28: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/28.jpg)
watchOSAuthorization
Shared with your iPhone app
![Page 29: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/29.jpg)
watchOSAuthorization
Shared with your iPhone appApproval requires interaction with iPhone
![Page 30: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/30.jpg)
watchOSAuthorization
Shared with your iPhone appApproval requires interaction with iPhone• May not be easily accessible
![Page 31: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/31.jpg)
watchOSAuthorization
Shared with your iPhone appApproval requires interaction with iPhone• May not be easily accessible• May be out of range
![Page 32: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/32.jpg)
Best practicesAuthorization
![Page 33: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/33.jpg)
Best practicesAuthorization
Make initial requests in sensible groupings of types
![Page 34: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/34.jpg)
Best practicesAuthorization
Make initial requests in sensible groupings of typesOption: Request all your app’s types during on-boarding
![Page 35: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/35.jpg)
Best practicesAuthorization
Make initial requests in sensible groupings of typesOption: Request all your app’s types during on-boardingReset authorization frequently during development
![Page 36: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/36.jpg)
Best practicesAuthorization
Make initial requests in sensible groupings of typesOption: Request all your app’s types during on-boardingReset authorization frequently during developmentTest delaying/denying authorization
![Page 37: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/37.jpg)
Best practicesAuthorization
Make initial requests in sensible groupings of typesOption: Request all your app’s types during on-boardingReset authorization frequently during developmentTest delaying/denying authorizationDo what’s best for the user
![Page 38: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/38.jpg)
Activity Rings
![Page 39: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/39.jpg)
![Page 40: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/40.jpg)
HKActivitySummaryActivity Rings
![Page 41: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/41.jpg)
HKActivitySummaryActivity Rings
Daily activity values
![Page 42: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/42.jpg)
HKActivitySummaryActivity Rings
Daily activity values• Move calories and goal
![Page 43: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/43.jpg)
HKActivitySummaryActivity Rings
Daily activity values• Move calories and goal• Exercise minutes and goal
![Page 44: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/44.jpg)
HKActivitySummaryActivity Rings
Daily activity values• Move calories and goal• Exercise minutes and goal• Stand hours and goal
![Page 45: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/45.jpg)
HKActivitySummaryActivity Rings
![Page 46: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/46.jpg)
HKActivitySummaryActivity Rings
Distinct type for authorization
![Page 47: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/47.jpg)
HKActivitySummaryActivity Rings
Distinct type for authorizationDaily aggregated totals
![Page 48: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/48.jpg)
HKActivitySummaryActivity Rings
Distinct type for authorizationDaily aggregated totalsDay specified as DateComponents
![Page 49: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/49.jpg)
// HKActivitySummaryQuery
import HealthKit
let healthStore = HKHealthStore()
let calendar = Calendar.current()
var components = calendar.components([.era, .year, .month, .day], from:Date())
components.calendar = calendar
let predicate = Predicate(format: "%K = %@", HKPredicateKeyPathDateComponents, components)
let query = HKActivitySummaryQuery(predicate: predicate) { query, summaries, error in
guard let todayActivitySummary = summaries?.first else { return }
// Display todayActivitySummary's data.
}
healthStore.execute(query)
![Page 50: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/50.jpg)
// HKActivitySummaryQuery
import HealthKit
let healthStore = HKHealthStore()
let calendar = Calendar.current()
var components = calendar.components([.era, .year, .month, .day], from:Date())
components.calendar = calendar
let predicate = Predicate(format: "%K = %@", HKPredicateKeyPathDateComponents, components)
let query = HKActivitySummaryQuery(predicate: predicate) { query, summaries, error in
guard let todayActivitySummary = summaries?.first else { return }
// Display todayActivitySummary's data.
}
healthStore.execute(query)
![Page 51: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/51.jpg)
// HKActivitySummaryQuery
import HealthKit
let healthStore = HKHealthStore()
let calendar = Calendar.current()
var components = calendar.components([.era, .year, .month, .day], from:Date())
components.calendar = calendar
let predicate = Predicate(format: "%K = %@", HKPredicateKeyPathDateComponents, components)
let query = HKActivitySummaryQuery(predicate: predicate) { query, summaries, error in
guard let todayActivitySummary = summaries?.first else { return }
// Display todayActivitySummary's data.
}
healthStore.execute(query)
![Page 52: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/52.jpg)
// HKActivitySummaryQuery
import HealthKit
let healthStore = HKHealthStore()
let calendar = Calendar.current()
var components = calendar.components([.era, .year, .month, .day], from:Date())
components.calendar = calendar
let predicate = Predicate(format: "%K = %@", HKPredicateKeyPathDateComponents, components)
let query = HKActivitySummaryQuery(predicate: predicate) { query, summaries, error in
guard let todayActivitySummary = summaries?.first else { return }
// Display todayActivitySummary's data.
}
healthStore.execute(query)
![Page 53: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/53.jpg)
HKActivityRingView and WKInterfaceActivityRingActivity Rings
![Page 54: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/54.jpg)
HKActivityRingView and WKInterfaceActivityRingActivity Rings
![Page 55: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/55.jpg)
HKActivityRingView and WKInterfaceActivityRingActivity Rings
![Page 56: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/56.jpg)
TipsActivity Rings
![Page 57: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/57.jpg)
TipsActivity Rings
Rings look best on black background
![Page 58: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/58.jpg)
TipsActivity Rings
Rings look best on black backgroundConstruct an HKActivitySummary to represent another user’s rings
![Page 59: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/59.jpg)
TipsActivity Rings
Rings look best on black backgroundConstruct an HKActivitySummary to represent another user’s ringsProvide era, year, month, and day in your DateComponents
![Page 60: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/60.jpg)
TipsActivity Rings
Rings look best on black backgroundConstruct an HKActivitySummary to represent another user’s ringsProvide era, year, month, and day in your DateComponents
Solutions to Common Date and Time Challenges WWDC 2013
![Page 61: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/61.jpg)
DemoAuthorization and activity rings
![Page 62: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/62.jpg)
Health Records
Jeff KibuuleiOS Software Engineer
![Page 63: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/63.jpg)
Current experienceHealth Records
![Page 64: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/64.jpg)
Current experienceHealth Records
![Page 65: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/65.jpg)
Current experienceHealth Records
![Page 66: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/66.jpg)
Current experienceHealth Records
![Page 67: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/67.jpg)
OverviewHealth Records NEW
![Page 68: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/68.jpg)
OverviewHealth Records
Represent different types of patient visits
NEW
![Page 69: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/69.jpg)
OverviewHealth Records
Represent different types of patient visits
NEW
![Page 70: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/70.jpg)
OverviewHealth Records
Represent different types of patient visitsSupport international HL-7 CDA standard
NEW
![Page 71: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/71.jpg)
OverviewHealth Records
Represent different types of patient visitsSupport international HL-7 CDA standardAvailable through patient health care portals
NEW
![Page 72: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/72.jpg)
OverviewHealth Records
Represent different types of patient visitsSupport international HL-7 CDA standardAvailable through patient health care portalsImported via Safari, Mail, and your apps
NEW
![Page 73: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/73.jpg)
OverviewHealth Records
Represent different types of patient visitsSupport international HL-7 CDA standardAvailable through patient health care portalsImported via Safari, Mail, and your appsStored securely
NEW
![Page 74: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/74.jpg)
PermissionsHealth Records
![Page 75: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/75.jpg)
PermissionsHealth Records
Access granted on a per document basis
![Page 76: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/76.jpg)
PermissionsHealth Records
Access granted on a per document basisUI presented to grant access
![Page 77: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/77.jpg)
PermissionsHealth Records
Access granted on a per document basisUI presented to grant accessQueries will…
![Page 78: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/78.jpg)
PermissionsHealth Records
Access granted on a per document basisUI presented to grant accessQueries will…• Prompt UI if new documents available
![Page 79: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/79.jpg)
PermissionsHealth Records
Access granted on a per document basisUI presented to grant accessQueries will…• Prompt UI if new documents available• Return immediately if no new documents
![Page 80: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/80.jpg)
PermissionsHealth Records
Access granted on a per document basisUI presented to grant accessQueries will…• Prompt UI if new documents available• Return immediately if no new documents• Never prompt in background
![Page 81: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/81.jpg)
CreatingHealth Records
![Page 82: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/82.jpg)
CreatingHealth Records
Save raw XML document as Data into HKCDADocumentSample type
![Page 83: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/83.jpg)
CreatingHealth Records
Save raw XML document as Data into HKCDADocumentSample type Validated on sample creation
![Page 84: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/84.jpg)
CreatingHealth Records
Save raw XML document as Data into HKCDADocumentSample type Validated on sample creationTitle, patient, custodian, and author names extracted automatically
![Page 85: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/85.jpg)
// Creating a Health Document Using HKCDADocumentSample
let today = Date()
let documentData: Data = ... // XML from health organization server
do {
let cdaSample = try HKCDADocumentSample.init(data: documentData, start: today, end:
today, metadata: nil)
healthStore.save(cdaSample) { success, error in
// Handle saving error here...
}
} catch {
// Handle validation error creating sample here...
}
![Page 86: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/86.jpg)
// Creating a Health Document Using HKCDADocumentSample
let today = Date()
let documentData: Data = ... // XML from health organization server
do {
let cdaSample = try HKCDADocumentSample.init(data: documentData, start: today, end:
today, metadata: nil)
healthStore.save(cdaSample) { success, error in
// Handle saving error here...
}
} catch {
// Handle validation error creating sample here...
}
![Page 87: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/87.jpg)
// Creating a Health Document Using HKCDADocumentSample
let today = Date()
let documentData: Data = ... // XML from health organization server
do {
let cdaSample = try HKCDADocumentSample.init(data: documentData, start: today, end:
today, metadata: nil)
healthStore.save(cdaSample) { success, error in
// Handle saving error here...
}
} catch {
// Handle validation error creating sample here...
}
![Page 88: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/88.jpg)
// Creating a Health Document Using HKCDADocumentSample
let today = Date()
let documentData: Data = ... // XML from health organization server
do {
let cdaSample = try HKCDADocumentSample.init(data: documentData, start: today, end:
today, metadata: nil)
healthStore.save(cdaSample) { success, error in
// Handle saving error here...
}
} catch {
// Handle validation error creating sample here...
}
![Page 89: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/89.jpg)
QueryingHealth Records
![Page 90: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/90.jpg)
QueryingHealth Records
Existing query objects continue to work
![Page 91: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/91.jpg)
QueryingHealth Records
Existing query objects continue to workNeed to use HKDocumentQuery to fetch raw XML
![Page 92: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/92.jpg)
QueryingHealth Records
Existing query objects continue to workNeed to use HKDocumentQuery to fetch raw XMLPredicate support for searching based on extracted fields
![Page 93: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/93.jpg)
QueryingHealth Records
Existing query objects continue to workNeed to use HKDocumentQuery to fetch raw XMLPredicate support for searching based on extracted fieldsDocument updates are considered new documents
![Page 94: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/94.jpg)
// Querying for Health Documents Using HKDocumentQuery
guard let documentType = HKObjectType.documentType(forIdentifier: .CDA) else { return }
let cdaQuery = HKDocumentQuery(documentType: documentType, predicate: nil, limit:
HKObjectQueryNoLimit, sortDescriptors: nil, includeDocumentData: false) { query, samples,
done, error in
// Handle HKCDADocumentSamples here...
}
healthStore.execute(cdaQuery)
![Page 95: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/95.jpg)
// Querying for Health Documents Using HKDocumentQuery
guard let documentType = HKObjectType.documentType(forIdentifier: .CDA) else { return }
let cdaQuery = HKDocumentQuery(documentType: documentType, predicate: nil, limit:
HKObjectQueryNoLimit, sortDescriptors: nil, includeDocumentData: false) { query, samples,
done, error in
// Handle HKCDADocumentSamples here...
}
healthStore.execute(cdaQuery)
![Page 96: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/96.jpg)
// Querying for Health Documents Using HKDocumentQuery
guard let documentType = HKObjectType.documentType(forIdentifier: .CDA) else { return }
let cdaQuery = HKDocumentQuery(documentType: documentType, predicate: nil, limit:
HKObjectQueryNoLimit, sortDescriptors: nil, includeDocumentData: false) { query, samples,
done, error in
// Handle HKCDADocumentSamples here...
}
healthStore.execute(cdaQuery)
![Page 97: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/97.jpg)
// Querying for Health Documents Using HKDocumentQuery
guard let documentType = HKObjectType.documentType(forIdentifier: .CDA) else { return }
let cdaQuery = HKDocumentQuery(documentType: documentType, predicate: nil, limit:
HKObjectQueryNoLimit, sortDescriptors: nil, includeDocumentData: false) { query, samples,
done, error in
// Handle HKCDADocumentSamples here...
}
healthStore.execute(cdaQuery)
![Page 98: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/98.jpg)
// Querying for Health Documents Using HKDocumentQuery
guard let documentType = HKObjectType.documentType(forIdentifier: .CDA) else { return }
let cdaQuery = HKDocumentQuery(documentType: documentType, predicate: nil, limit:
HKObjectQueryNoLimit, sortDescriptors: nil, includeDocumentData: false) { query, samples,
done, error in
// Handle HKCDADocumentSamples here...
}
healthStore.execute(cdaQuery)
![Page 99: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/99.jpg)
Best practicesHealth Records
![Page 100: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/100.jpg)
Best practicesHealth Records
Check validation errors
![Page 101: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/101.jpg)
Best practicesHealth Records
Check validation errorsVerify with Health app
![Page 102: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/102.jpg)
Best practicesHealth Records
Check validation errorsVerify with Health appRequest raw XML document only when needed
![Page 103: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/103.jpg)
http://www.hl7.org/implement/standards/product_brief.cfm?product_id=7
HL-7 CDA Standard
![Page 104: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/104.jpg)
Handling Data
![Page 105: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/105.jpg)
Handling Data
![Page 106: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/106.jpg)
Handling Data
YourApp
App#3
App#2
![Page 107: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/107.jpg)
Handling Data
YourApp
App#3
App#2
![Page 108: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/108.jpg)
Handling Data
YourApp
Your Cloud
App#3
App#2
![Page 109: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/109.jpg)
Handling Data
YourApp
Your Cloud
App#3
App #2Cloud
App#2
![Page 110: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/110.jpg)
Handling Data
![Page 111: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/111.jpg)
Handling Data
Syncing data
![Page 112: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/112.jpg)
Handling Data
Syncing dataTracking changed data
![Page 113: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/113.jpg)
Handling Data
Syncing dataTracking changed dataMigrating data
![Page 114: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/114.jpg)
Syncing dataHandling Data
![Page 115: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/115.jpg)
Syncing dataHandling Data
Use HKAnchoredObjectQuery
![Page 116: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/116.jpg)
Syncing dataHandling Data
Use HKAnchoredObjectQueryAnchors let you pick up where you last left off
![Page 117: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/117.jpg)
Syncing dataHandling Data
Use HKAnchoredObjectQueryAnchors let you pick up where you last left offOne query per sample type
![Page 118: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/118.jpg)
Syncing dataHandling Data
Use HKAnchoredObjectQueryAnchors let you pick up where you last left offOne query per sample typeUse an update handler
![Page 119: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/119.jpg)
Background updatesHandling Data
![Page 120: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/120.jpg)
Background updatesHandling Data
Setup
Execution
![Page 121: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/121.jpg)
Background updatesHandling Data
Register for Background Updates1
Setup
Execution
![Page 122: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/122.jpg)
Background updatesHandling Data
Register for Background Updates
OpenHKObserverQuery
1
2Setup
Execution
![Page 123: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/123.jpg)
Background updatesHandling Data
Register for Background Updates
OpenHKObserverQuery
HKObserverQuery callback;Execute
HKAnchoredObjectQuery
1
2
3
Setup
Execution
![Page 124: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/124.jpg)
Background updatesHandling Data
Register for Background Updates
OpenHKObserverQuery
HKObserverQuery callback;Execute
HKAnchoredObjectQuery
Call HKObserverQueryCompletion Handler
1
2
3
4
Setup
Execution
![Page 125: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/125.jpg)
Background updatesHandling Data
Register for Background Updates
OpenHKObserverQuery
HKObserverQuery callback;Execute
HKAnchoredObjectQuery
Call HKObserverQueryCompletion Handler
1
2
3
4
Setup
Execution
![Page 126: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/126.jpg)
// Syncing Data
// 1. Register for background updates
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:
[NSObject: AnyObject]?) -> Bool {
guard let stepsType = HKObjectType.quantityType(forIdentifier: .stepCount) else {
return true
}
healthStore.enableBackgroundDelivery(for: stepsType, frequency: .daily) {
success, error in
// Handle enabling background delivery error here...
}
return true
}
![Page 127: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/127.jpg)
// Syncing Data
// 1. Register for background updates
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:
[NSObject: AnyObject]?) -> Bool {
guard let stepsType = HKObjectType.quantityType(forIdentifier: .stepCount) else {
return true
}
healthStore.enableBackgroundDelivery(for: stepsType, frequency: .daily) {
success, error in
// Handle enabling background delivery error here...
}
return true
}
![Page 128: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/128.jpg)
// Syncing Data
// 1. Register for background updates
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:
[NSObject: AnyObject]?) -> Bool {
guard let stepsType = HKObjectType.quantityType(forIdentifier: .stepCount) else {
return true
}
healthStore.enableBackgroundDelivery(for: stepsType, frequency: .daily) {
success, error in
// Handle enabling background delivery error here...
}
return true
}
![Page 129: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/129.jpg)
// Syncing Data
// 1. Register for background updates
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:
[NSObject: AnyObject]?) -> Bool {
guard let stepsType = HKObjectType.quantityType(forIdentifier: .stepCount) else {
return true
}
healthStore.enableBackgroundDelivery(for: stepsType, frequency: .daily) {
success, error in
// Handle enabling background delivery error here...
}
return true
}
![Page 130: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/130.jpg)
// Syncing Data
// 2. Open observer query
guard let stepsType = HKObjectType.quantityType(forIdentifier: .stepCount) else { return }
let query = HKObserverQuery(sampleType: stepsType, predicate: nil) {
query, completionHandler, error in
self.updateSteps() {
completionHandler()
}
}
healthStore.execute(query)
![Page 131: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/131.jpg)
// Syncing Data
// 2. Open observer query
guard let stepsType = HKObjectType.quantityType(forIdentifier: .stepCount) else { return }
let query = HKObserverQuery(sampleType: stepsType, predicate: nil) {
query, completionHandler, error in
self.updateSteps() {
completionHandler()
}
}
healthStore.execute(query)
![Page 132: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/132.jpg)
// Syncing Data
// 2. Open observer query
guard let stepsType = HKObjectType.quantityType(forIdentifier: .stepCount) else { return }
let query = HKObserverQuery(sampleType: stepsType, predicate: nil) {
query, completionHandler, error in
self.updateSteps() {
completionHandler()
}
}
healthStore.execute(query)
![Page 133: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/133.jpg)
// Syncing Data
// 2. Open observer query
guard let stepsType = HKObjectType.quantityType(forIdentifier: .stepCount) else { return }
let query = HKObserverQuery(sampleType: stepsType, predicate: nil) {
query, completionHandler, error in
self.updateSteps() {
completionHandler()
}
}
healthStore.execute(query)
![Page 134: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/134.jpg)
// Syncing Data
// 3. Execute anchored objected query
func updateSteps(completionHandler: () -> Void) {
guard let stepsType = HKObjectType.quantityType(forIdentifier: .stepCount) else {return}
let anchoredQuery = HKAnchoredObjectQuery(type: stepsType, predicate: nil, anchor:
self.anchor, limit: Int(HKObjectQueryNoLimit)) { [unowned self] query, newSamples,
deletedSamples, newAnchor, error -> Void in
self.handleSteps(new: newSamples, deleted: deletedSamples)
self.update(anchor: newAnchor)
completionHandler()
}
healthStore.execute(anchoredQuery)
}
![Page 135: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/135.jpg)
// Syncing Data
// 3. Execute anchored objected query
func updateSteps(completionHandler: () -> Void) {
guard let stepsType = HKObjectType.quantityType(forIdentifier: .stepCount) else {return}
let anchoredQuery = HKAnchoredObjectQuery(type: stepsType, predicate: nil, anchor:
self.anchor, limit: Int(HKObjectQueryNoLimit)) { [unowned self] query, newSamples,
deletedSamples, newAnchor, error -> Void in
self.handleSteps(new: newSamples, deleted: deletedSamples)
self.update(anchor: newAnchor)
completionHandler()
}
healthStore.execute(anchoredQuery)
}
![Page 136: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/136.jpg)
// Syncing Data
// 3. Execute anchored objected query
func updateSteps(completionHandler: () -> Void) {
guard let stepsType = HKObjectType.quantityType(forIdentifier: .stepCount) else {return}
let anchoredQuery = HKAnchoredObjectQuery(type: stepsType, predicate: nil, anchor:
self.anchor, limit: Int(HKObjectQueryNoLimit)) { [unowned self] query, newSamples,
deletedSamples, newAnchor, error -> Void in
self.handleSteps(new: newSamples, deleted: deletedSamples)
self.update(anchor: newAnchor)
completionHandler()
}
healthStore.execute(anchoredQuery)
}
![Page 137: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/137.jpg)
// Syncing Data
// 3. Execute anchored objected query
func updateSteps(completionHandler: () -> Void) {
guard let stepsType = HKObjectType.quantityType(forIdentifier: .stepCount) else {return}
let anchoredQuery = HKAnchoredObjectQuery(type: stepsType, predicate: nil, anchor:
self.anchor, limit: Int(HKObjectQueryNoLimit)) { [unowned self] query, newSamples,
deletedSamples, newAnchor, error -> Void in
self.handleSteps(new: newSamples, deleted: deletedSamples)
self.update(anchor: newAnchor)
completionHandler()
}
healthStore.execute(anchoredQuery)
}
![Page 138: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/138.jpg)
// Syncing Data
// 3. Execute anchored objected query
func updateSteps(completionHandler: () -> Void) {
guard let stepsType = HKObjectType.quantityType(forIdentifier: .stepCount) else {return}
let anchoredQuery = HKAnchoredObjectQuery(type: stepsType, predicate: nil, anchor:
self.anchor, limit: Int(HKObjectQueryNoLimit)) { [unowned self] query, newSamples,
deletedSamples, newAnchor, error -> Void in
self.handleSteps(new: newSamples, deleted: deletedSamples)
self.update(anchor: newAnchor)
completionHandler()
}
healthStore.execute(anchoredQuery)
}
![Page 139: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/139.jpg)
// Syncing Data
// 3. Execute anchored objected query
func updateSteps(completionHandler: () -> Void) {
guard let stepsType = HKObjectType.quantityType(forIdentifier: .stepCount) else {return}
let anchoredQuery = HKAnchoredObjectQuery(type: stepsType, predicate: nil, anchor:
self.anchor, limit: Int(HKObjectQueryNoLimit)) { [unowned self] query, newSamples,
deletedSamples, newAnchor, error -> Void in
self.handleSteps(new: newSamples, deleted: deletedSamples)
self.update(anchor: newAnchor)
completionHandler()
}
healthStore.execute(anchoredQuery)
}
![Page 140: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/140.jpg)
// Syncing Data
// 4. Call observer query completion handler
guard let stepsType = HKObjectType.quantityType(forIdentifier: .stepCount) else { return }
let query = HKObserverQuery(sampleType: stepsType, predicate: nil) {
query, completionHandler, error in
self.updateSteps() {
completionHandler()
}
}
healthStore.execute(query)
![Page 141: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/141.jpg)
// Syncing Data
// 4. Call observer query completion handler
guard let stepsType = HKObjectType.quantityType(forIdentifier: .stepCount) else { return }
let query = HKObserverQuery(sampleType: stepsType, predicate: nil) {
query, completionHandler, error in
self.updateSteps() {
completionHandler()
}
}
healthStore.execute(query)
![Page 142: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/142.jpg)
Tracking Changed Data
![Page 143: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/143.jpg)
Tracking Changed Data
Use UUIDs to keep track of unique HKObjects
![Page 144: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/144.jpg)
Tracking Changed Data
Use UUIDs to keep track of unique HKObjectsRecord UUIDs of HKObjects in your own data store
![Page 145: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/145.jpg)
Tracking Changed Data
Use UUIDs to keep track of unique HKObjectsRecord UUIDs of HKObjects in your own data storeWhen samples are deleted, remove data corresponding to those UUIDs
![Page 146: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/146.jpg)
Tracking Changed Data
Use UUIDs to keep track of unique HKObjectsRecord UUIDs of HKObjects in your own data storeWhen samples are deleted, remove data corresponding to those UUIDsEnsure sync doesn’t re-add already deleted samples
![Page 147: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/147.jpg)
Potential problemsDuplication
![Page 148: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/148.jpg)
Potential problemsDuplication
Pre-populating data during on-boarding saves time
![Page 149: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/149.jpg)
Potential problemsDuplication
Pre-populating data during on-boarding saves timeUsers can verify/change data
![Page 150: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/150.jpg)
Potential problemsDuplication
Pre-populating data during on-boarding saves timeUsers can verify/change dataProblem: Saving unchanged values
![Page 151: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/151.jpg)
Potential problemsDuplication
Pre-populating data during on-boarding saves timeUsers can verify/change dataProblem: Saving unchanged values• Only save data again if this is the
user’s intent
![Page 152: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/152.jpg)
Potential problemsDuplication
YourApp
App#2
![Page 153: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/153.jpg)
Potential problemsDuplication
Problem: Ingesting information from another app and HealthKit Your
AppApp#2
![Page 154: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/154.jpg)
Potential problemsDuplication
Problem: Ingesting information from another app and HealthKit• Pick only one source most appropriate
to your app
YourApp
App#2
![Page 155: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/155.jpg)
Potential problemsDuplication
Problem: Ingesting information from another app and HealthKit• Pick only one source most appropriate
to your app• Do not save data on another app’s behalf
YourApp
App#2
![Page 156: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/156.jpg)
Potential problemsDuplication
Problem: Ingesting information from another app and HealthKit• Pick only one source most appropriate
to your app• Do not save data on another app’s behalf• Write only your own data once
YourApp
App#2
![Page 157: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/157.jpg)
ExceptionsDuplication
![Page 158: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/158.jpg)
ExceptionsDuplication
Sometimes duplication is intentional
![Page 159: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/159.jpg)
ExceptionsDuplication
Sometimes duplication is intentional• Data from multiple sources
![Page 160: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/160.jpg)
ExceptionsDuplication
Sometimes duplication is intentional• Data from multiple sources
HKStatisticsQuery and HKStatisticsCollectionQuery automatically de-duplicate data
![Page 161: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/161.jpg)
ExceptionsDuplication
Sometimes duplication is intentional• Data from multiple sources
HKStatisticsQuery and HKStatisticsCollectionQuery automatically de-duplicate data Order of preferred data sources can change in Health app
![Page 162: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/162.jpg)
Migrating Data
![Page 163: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/163.jpg)
Migrating Data
![Page 164: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/164.jpg)
Migrating Data
98° C
![Page 165: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/165.jpg)
Migrating Data
Find Old Samples
98° C
![Page 166: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/166.jpg)
Migrating Data
Find Old Samples
Write New Samples
98° F98° C
![Page 167: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/167.jpg)
Migrating Data
Find Old Samples
Write New Samples
Delete Old Samples
98° F
![Page 168: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/168.jpg)
Flow between iPhone and Apple WatchHandling Data NEW
![Page 169: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/169.jpg)
Flow between iPhone and Apple WatchHandling Data
Recent samples from iPhone are periodically synced to Apple Watch
Time
iOS 9.3
iPhone Apple Watch
NEW
![Page 170: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/170.jpg)
Flow between iPhone and Apple WatchHandling Data
Recent samples from iPhone are periodically synced to Apple WatchSamples on Apple Watch are pruned by end date
Time
iOS 9.3
iPhone Apple Watch
NEW
![Page 171: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/171.jpg)
Flow between iPhone and Apple WatchHandling Data
Recent samples from iPhone are periodically synced to Apple WatchSamples on Apple Watch are pruned by end dateSave samples with endDate after HKHealthStore’s earliestPermittedSampleDate
Time
iOS 9.3
iPhone Apple Watch
NEW
![Page 172: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/172.jpg)
Flow between iPhone and Apple WatchHandling Data
Recent samples from iPhone are periodically synced to Apple WatchSamples on Apple Watch are pruned by end dateSave samples with endDate after HKHealthStore’s earliestPermittedSampleDate
Save samples on iPhone or Apple Watch, not both
Time
iOS 9.3
iPhone Apple Watch
NEW
![Page 173: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/173.jpg)
Wheelchair Support
![Page 174: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/174.jpg)
![Page 175: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/175.jpg)
Wheelchair Support NEW
![Page 176: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/176.jpg)
Wheelchair Support
New characteristic data type
NEW
![Page 177: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/177.jpg)
Wheelchair Support
New characteristic data typeNew quantity types
NEW
![Page 178: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/178.jpg)
Wheelchair Support
New characteristic data typeNew quantity typesNew workout activity types
NEW
![Page 179: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/179.jpg)
DetailsWheelchair Support NEW
![Page 180: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/180.jpg)
DetailsWheelchair Support
Steps → Push count
NEW
![Page 181: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/181.jpg)
DetailsWheelchair Support
Steps → Push count
Stand hours → Roll hours
NEW
![Page 182: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/182.jpg)
DetailsWheelchair Support
Steps → Push count
Stand hours → Roll hoursWheelchair distance only recorded during workouts
NEW
![Page 183: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/183.jpg)
DetailsWheelchair Support
Steps → Push count
Stand hours → Roll hoursWheelchair distance only recorded during workoutsWheelchair use status can change over time
NEW
![Page 184: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/184.jpg)
Summary
![Page 185: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/185.jpg)
Summary
Pay attention to the authorization user experience
![Page 186: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/186.jpg)
Summary
Pay attention to the authorization user experienceIncorporate Apple’s activity rings into your app
![Page 187: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/187.jpg)
Summary
Pay attention to the authorization user experienceIncorporate Apple’s activity rings into your appTake care when handling and synchronizing HealthKit data
![Page 188: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/188.jpg)
Summary
Pay attention to the authorization user experienceIncorporate Apple’s activity rings into your appTake care when handling and synchronizing HealthKit dataMake your experience accessible to wheelchair users
![Page 189: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/189.jpg)
More Information
https://developer.apple.com/wwdc16/209
![Page 190: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/190.jpg)
Related Sessions
Health and Fitness with Core Motion Nob Hill Thursday 3:00PM
What’s New in ResearchKit Nob Hill Friday 10:00AM
Building Great Workout Apps Pacific Heights Friday 11:00AM
Getting Started with CareKit Pacific Heights Friday 3:00PM
Introducing HealthKit WWDC 2014
Designing Accessories for iOS and OS X WWDC 2014
What’s New in HealthKit WWDC 2015
![Page 191: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/191.jpg)
Labs
HealthKit Lab Frameworks Lab A Wednesday 10:00AM
HealthKit Lab Frameworks Lab A Thursday 9:00AM
ResearchKit and CareKit Lab Fort Mason Friday 10:30AM
Core Motion Lab Frameworks Lab D Friday 12:30PM
ResearchKit and CareKit Lab Fort Mason Friday 3:30PM
![Page 192: Getting the Most Out of HealthKit - Apple Developer€¦ · Health Records Represent different types of patient visits Support international HL-7 CDA standard Available through patient](https://reader035.vdocuments.site/reader035/viewer/2022063014/5fd1341d70a0da3bfd381429/html5/thumbnails/192.jpg)