-
Measure health with motion
Discover how you can take your app's health monitoring to the next level with motion data. Meet Walking Steadiness for iPhone and the six-minute-walk metric for Apple Watch: Walking Steadiness can help your app interpret someone's quality of walking and risk of falling, while the six-minute-walk metric — along with the HealthKit estimate recalibration API — can track changes to walking endurance following acute events like surgery. We'll show you how you can support these metrics and help provide actionable health data to people who use your app, helping improve patient care and clinical trials, especially as more services must be delivered remotely.
Ressources
- HKAppleWalkingSteadinessClassification
- appleWalkingSteadinessEvent
- appleWalkingSteadiness
- CMFallDetectionManager
- Measuring Walking Quality Through iPhone Mobility Metrics
- Using Apple Watch to Estimate Six-Minute Walk Distance
- Using Apple Watch to Estimate Cardio Fitness with VO2 max
- Getting movement disorder symptom data
- Core Motion
Vidéos connexes
WWDC20
-
Rechercher dans cette vidéo…
-
-
0:01 - Grab authorization to read and share sixMinuteWalkTestDistance type
// Grab authorization to read and share sixMinuteWalkTestDistance type let healthStore = HKHealthStore() let types: Set = [ HKObjectType.quantityType(forIdentifier: .sixMinuteWalkTestDistance)! ] healthStore.requestAuthorization(toShare: types, read: types) { _, _ in } -
0:02 - Recalibrate Six-Minute Walk estimates
// Recalibrate estimate let healthStore = HKHealthStore() let sixMinuteWalkType = HKSampleType.quantityType(forIdentifier: .sixMinuteWalkTestDistance)! if sixMinuteWalkType.allowsRecalibrationForEstimates { healthStore.recalibrateEstimates(sampleType: sixMinuteWalkType, date: surgeryDate) { (success, error) in // Handle error } } -
0:03 - Get authorized for walkingSteadiness type
// Get authorized let types: Set = [ HKObjectType.quantityType(forIdentifier: .walkingSteadiness)! ] healthKitStore.requestAuthorization(toShare: nil, read: types) { _, _ in } -
0:04 - Construct a query for most recent walkingSteadiness score
// Construct a query for most recent walkingSteadiness score let steadinessType = HKObjectType.quantityType(forIdentifier: .walkingSteadiness) let sortByEndDate = NSSortDescriptor(key: HKSampleSortIdentifierEndDate, ascending: false) let query = HKSampleQuery(sampleType: steadinessType, predicate: nil, limit: 1, sortDescriptors: [sortByEndDate]) { (query, samples, error) in if let sample = samples?.first as? HKQuantitySample{ let recentScore = sample.quantity.doubleValue(forUnit: .percentUnit) updateStatus(score: recentScore) } } self.healthStore.execute(query) -
0:05 - Construct a query for most recent walkingSteadiness classification
// Construct a query for most recent walkingSteadiness classification let steadinessType = HKObjectType.quantityType(forIdentifier: .walkingSteadiness) let query = HKSampleQuery(sampleType: steadinessType, predicate: nil, limit: 1, sortDescriptors: nil) { (query, samples, error) in if let sample = samples?.first as? HKQuantitySample{ let recentScore = sample.quantity.doubleValue(forUnit: .percentUnit) // Use HealthKit API to classify a value as OK, Low, or Very Low let recentClassification = HKAppleWalkingSteadinessClassification(for: walkingSteadiness.quantity) updateStatus(classification: recentClassification, score: recentScore) } } self.healthStore.execute(query) -
0:06 - Get authorized .walkingSteadinessEvent
// Get authorized let types: Set = [ HKObjectType.categoryType(forIdentifier: .walkingSteadinessEvent)! ] healthKitStore.requestAuthorization(toShare: nil, read: types) { _, _ in } -
0:07 - Watch for walkingSteadiness notifications
// Watch for walkingSteadiness notifications let notificationType = HKCategoryType.categoryType(forIdentifier: .appleWalkingSteadinessEvent)! let query = HKObserverQuery(sampleType: notificationType, predicate: nil) { (query, completionHandler, errorOrNil) in if let error = errorOrNil { // Properly handle the error. return } promptCheckupForNotification() completionHandler() } self.healthStore.execute(query) -
0:08 - Query walking steadiness in the past 6 weeks
// Query samples from HealthKit // Look back 6 weeks let end = Date() let start = Calendar.current.date(byAdding: .week, value: -6, to: end) let datePredicate = HKQuery.predicateForSamples(withStart: start, end: end, options: []) // Query walking steadiness let steadinessType = HKObjectType.quantityType(forIdentifier: .walkingSteadiness) let sortByEndDate = NSSortDescriptor(key: HKSampleSortIdentifierEndDate, ascending: false) let query = HKSampleQuery(sampleType: steadinessType, predicate: sortByEndDate, limit: nil, sortDescriptors:[sortByEndDate]) { (_, samples, _) in detectTrends(samples) } self.healthStore.execute(query)
-