•what’s new in health - apple developer · 2017-06-08 · alexa vanhattum, ios software...

201
#WWDC17 © 2017 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer What’s New in Health Session 221 App Frameworks

Upload: others

Post on 19-Apr-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

#WWDC17

© 2017 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer

•What’s New in Health • Session 221

App Frameworks

Page 2: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for
Page 3: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for
Page 4: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for
Page 5: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for
Page 6: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

•New HealthKit types •Workout API updates •Sync identifiers •Supporting diabetes management

Page 7: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

•New HealthKit types •Workout API updates •Sync identifiers •Supporting diabetes management

Page 8: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

•New HealthKit types •Workout API updates •Sync identifiers •Supporting diabetes management

Page 9: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

•New HealthKit types •Workout API updates •Sync identifiers •Supporting diabetes management

Page 10: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

•New HealthKit types •Workout API updates •Sync identifiers •Supporting diabetes management

Page 11: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

•New HealthKit Types

Page 12: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Sample Types NEW

Page 13: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Sample Types

Workout route • HKWorkoutRouteTypeIdentifier

NEW

Page 14: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Sample Types

Workout route • HKWorkoutRouteTypeIdentifier

Waist circumference • HKQuantityTypeIdentifierWaistCircumference

NEW

Page 15: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Sample Types

Workout route • HKWorkoutRouteTypeIdentifier

Waist circumference • HKQuantityTypeIdentifierWaistCircumference

VO2 max • HKQuantityTypeIdentifierVO2Max

NEW

Page 16: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Sample Types

Workout route • HKWorkoutRouteTypeIdentifier

Waist circumference • HKQuantityTypeIdentifierWaistCircumference

VO2 max • HKQuantityTypeIdentifierVO2Max

Insulin delivery • HKQuantityTypeIdentifierInsulinDelivery

NEW

Page 17: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Workout Activity Types NEW

Page 18: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Workout Activity Types NEW

Tai chi • HKWorkoutRouteType.Taichi

Page 19: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Workout Activity Types NEW

Tai chi • HKWorkoutRouteType.Taichi

Mixed cardio • HKWorkoutActivityType.MixedCardio

Page 20: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Workout Activity Types

Tai chi • HKWorkoutRouteType.Taichi

Mixed cardio • HKWorkoutActivityType.MixedCardio

Hand cycling • HKWorkoutActivityType.HandCycling

NEW

Page 21: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

•Workout API Updates •Swimming, segments, and pause/resume

Page 22: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for
Page 23: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Support for pool and open water

Swimming Tracking with Apple Watch

Page 24: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Support for pool and open water

Automatic swimming metrics

Swimming Tracking with Apple Watch

Page 25: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Support for pool and open water

Automatic swimming metrics • Swimming distance

Swimming Tracking with Apple Watch

Page 26: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Support for pool and open water

Automatic swimming metrics • Swimming distance • Stroke count

Swimming Tracking with Apple Watch

Page 27: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Support for pool and open water

Automatic swimming metrics • Swimming distance • Stroke count • Individual lap detection

Swimming Tracking with Apple Watch

Page 28: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Support for pool and open water

Automatic swimming metrics • Swimming distance • Stroke count • Individual lap detection • Per-lap stroke style detection

Swimming Tracking with Apple Watch

Page 29: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Support for pool and open water

Automatic swimming metrics • Swimming distance • Stroke count • Individual lap detection • Per-lap stroke style detection • Set detection

Swimming Tracking with Apple Watch

NEW

Page 30: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Support for pool and open water

Automatic swimming metrics • Swimming distance • Stroke count • Individual lap detection • Per-lap stroke style detection • Set detection

Apps can enable water lock

NEWSwimming Tracking with Apple Watch

Page 31: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

public let HKMetadataKeySwimmingLocationType: String

Swimming Metadata keys and values

Page 32: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

public let HKMetadataKeySwimmingLocationType: String public enum HKWorkoutSwimmingLocationType : Int { case Unknown case Pool case OpenWater }

Swimming Metadata keys and values

Page 33: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

public let HKMetadataKeySwimmingStrokeStyle: String

Swimming Metadata keys and values

Page 34: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

public let HKMetadataKeySwimmingStrokeStyle: String public enum HKSwimmingStrokeStyle : Int { case Unknown case Mixed case Freestyle case Backstroke case Breaststroke case Butterfly }

Swimming Metadata keys and values

Page 35: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Swimming Workout configuration

let workoutConfiguration = HKWorkoutConfiguration()

Page 36: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Swimming Workout configuration

let workoutConfiguration = HKWorkoutConfiguration() workoutConfiguration.activityType = HKWorkoutActivityType.swimming

Page 37: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Swimming Workout configuration

let workoutConfiguration = HKWorkoutConfiguration() workoutConfiguration.activityType = HKWorkoutActivityType.swimming workoutConfiguration.swimmingLocationType = HKWorkoutSwimmingLocationType.pool

Page 38: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Swimming Workout configuration

let workoutConfiguration = HKWorkoutConfiguration() workoutConfiguration.activityType = HKWorkoutActivityType.swimming workoutConfiguration.swimmingLocationType = HKWorkoutSwimmingLocationType.pool workoutConfiguration.lapLength = HKQuantity(unit: .yard(), doubleValue: 25)

Page 39: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Swimming Workout configuration

let workoutConfiguration = HKWorkoutConfiguration() workoutConfiguration.activityType = HKWorkoutActivityType.swimming workoutConfiguration.swimmingLocationType = HKWorkoutSwimmingLocationType.pool workoutConfiguration.lapLength = HKQuantity(unit: .yard(), doubleValue: 25)

do { let workoutSession = try HKWorkoutSession(configuration: workoutConfiguration)

} catch let error { // Handle error... }

Page 40: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Swimming Workout configuration

let workoutConfiguration = HKWorkoutConfiguration() workoutConfiguration.activityType = HKWorkoutActivityType.swimming workoutConfiguration.swimmingLocationType = HKWorkoutSwimmingLocationType.pool workoutConfiguration.lapLength = HKQuantity(unit: .yard(), doubleValue: 25)

do { let workoutSession = try HKWorkoutSession(configuration: workoutConfiguration) workoutSession.delegate = self

} catch let error { // Handle error... }

Page 41: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Swimming Workout configuration

let workoutConfiguration = HKWorkoutConfiguration() workoutConfiguration.activityType = HKWorkoutActivityType.swimming workoutConfiguration.swimmingLocationType = HKWorkoutSwimmingLocationType.pool workoutConfiguration.lapLength = HKQuantity(unit: .yard(), doubleValue: 25)

do { let workoutSession = try HKWorkoutSession(configuration: workoutConfiguration) workoutSession.delegate = self healthStore.start(workoutSession) // ... } catch let error { // Handle error... }

Page 42: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

func workoutSession(_ workoutSession: HKWorkoutSession, didChangeTo toState: HKWorkoutSessionState, from fromState: HKWorkoutSessionState, date: Date) {

}

Swimming Enable water lock

Page 43: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

func workoutSession(_ workoutSession: HKWorkoutSession, didChangeTo toState: HKWorkoutSessionState, from fromState: HKWorkoutSessionState, date: Date) {

switch (fromState, toState) {

} }

Swimming Enable water lock

Page 44: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

func workoutSession(_ workoutSession: HKWorkoutSession, didChangeTo toState: HKWorkoutSessionState, from fromState: HKWorkoutSessionState, date: Date) {

switch (fromState, toState) { case (.notStarted, .running):

} }

Swimming Enable water lock

Page 45: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Swimming Enable water lock

func workoutSession(_ workoutSession: HKWorkoutSession, didChangeTo toState: HKWorkoutSessionState, from fromState: HKWorkoutSessionState, date: Date) {

switch (fromState, toState) { case (.notStarted, .running): let wkExtension = WKExtension.shared() wkExtension.enableWaterLock() // ... } }

Page 46: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

HKWorkoutEvent

Highlight a specific time in the workout

Page 47: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

HKWorkoutEvent

Highlight a specific time in the workout

Used for pausing, resuming, laps, and markers

Page 48: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

HKWorkoutEvent

Highlight a specific time in the workout

Used for pausing, resuming, laps, and markers

Created by HealthKit or your app

Page 49: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

HKWorkoutEvent

Highlight a specific time in the workout

Used for pausing, resuming, laps, and markers

Created by HealthKit or your app

Save a list on HKWorkout

Page 50: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

HKWorkoutEvent

Highlight a specific time in the workout

Used for pausing, resuming, laps, and markers

Created by HealthKit or your app

Save a list on HKWorkout

Affect the workout’s duration

Page 51: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// In your workout session’s delegate func workoutSession(_ workoutSession: HKWorkoutSession, didGenerate event: HKWorkoutEvent) {

}

Swimming Observing lap events

Page 52: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// In your workout session’s delegate func workoutSession(_ workoutSession: HKWorkoutSession, didGenerate event: HKWorkoutEvent) { switch event.type {

} }

Swimming Observing lap events

Page 53: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// In your workout session’s delegate func workoutSession(_ workoutSession: HKWorkoutSession, didGenerate event: HKWorkoutEvent) { switch event.type { case .lap:

} }

Swimming Observing lap events

Page 54: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// In your workout session’s delegate func workoutSession(_ workoutSession: HKWorkoutSession, didGenerate event: HKWorkoutEvent) { switch event.type { case .lap: lapCount += 1

} }

Swimming Observing lap events

Page 55: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// In your workout session’s delegate func workoutSession(_ workoutSession: HKWorkoutSession, didGenerate event: HKWorkoutEvent) { switch event.type { case .lap: lapCount += 1 if let strokeStyle = event.metadata?[HKMetadataKeySwimmingStrokeStyle] { self.displayCurrentStrokeStyle(strokeStyle) } // ... } }

Swimming Observing lap events

Page 56: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

New Workout Events NEW

Page 57: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// HKWorkout.h

public enum HKWorkoutEventType : Int { case pause case resume case lap case marker case motionPaused case motionResumed

}

New Workout Events NEW

Page 58: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// HKWorkout.h

public enum HKWorkoutEventType : Int { case pause case resume case lap case marker case motionPaused case motionResumed

case segment case pauseOrResumeRequest }

New Workout Events NEW

Page 59: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// HKWorkout.h

public enum HKWorkoutEventType : Int { case pause case resume case lap case marker case motionPaused case motionResumed

case segment case pauseOrResumeRequest }

New Workout Events NEW

Page 60: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

HKWorkoutEvent.segment NEW

open class HKWorkoutEvent : NSObject, NSSecureCoding, NSCopying { open var date: Date { get }

public convenience init(type: HKWorkoutEventType, date: Date, metadata: [String : Any])

}

Page 61: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

HKWorkoutEvent.segment NEW

On HKWorkoutEvent: date → dateInterval

open class HKWorkoutEvent : NSObject, NSSecureCoding, NSCopying { open var date: Date { get } open var dateInterval: DateInterval { get }

public convenience init(type: HKWorkoutEventType, date: Date, metadata: [String : Any]) public convenience init(type: HKWorkoutEventType, dateInterval: DateInterval, metadata: [String : Any]?) }

Page 62: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Start workout

.type date interval {metadata}

Page 63: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Start workout

.type date interval {metadata}

Page 64: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Start workout

.type date interval {metadata}

Page 65: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Start workout

.type date interval {metadata}

Page 66: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Start workout

.type date interval {metadata}

Page 67: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Start workout

.type date interval {metadata}

.lap 2:00

{ .freestyle }

Page 68: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Start workout

.type date interval {metadata}

.lap 2:00

{ .freestyle }

.lap 3:00

{ .butterfly }

Page 69: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Start workout

.pause 3:30

{ }

.type date interval {metadata}

.lap 2:00

{ .freestyle }

.lap 3:00

{ .butterfly }

Page 70: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Start workout

.pause 3:30

{ }

.type date interval {metadata}

.lap 2:00

{ .freestyle }

.segment (0, 3:30)

{ }

.lap 3:00

{ .butterfly }

Page 71: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Start workout

.pause 3:30

{ }

.resume 4:30

{ }

.type date interval {metadata}

.lap 2:00

{ .freestyle }

.segment (0, 3:30)

{ }

.lap 3:00

{ .butterfly }

Page 72: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Start workout

.pause 3:30

{ }

.resume 4:30

{ }

.type date interval {metadata}

.lap 2:00

{ .freestyle }

.segment (0, 3:30)

{ }

.lap 6:30

{ .freestyle }

.lap 3:00

{ .butterfly }

Page 73: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Start workout

.pause 3:30

{ }

.resume 4:30

{ }

.type date interval {metadata}

.lap 2:00

{ .freestyle }

.segment (0, 3:30)

{ }

.segment (4:30, 6:30)

{ }

.lap 6:30

{ .freestyle }

.lap 3:00

{ .butterfly }

Page 74: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Start workout

.pause 3:30

{ }

.resume 4:30

{ }

.type date interval {metadata}

.lap 2:00

{ .freestyle }

.segment (0, 3:30)

{ }

.segment (4:30, 6:30)

{ }

.lap 6:30

{ .freestyle }

.lap 3:00

{ .butterfly }

Page 75: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Start workout End workout

.pause 3:30

{ }

.resume 4:30

{ }

.type date interval {metadata}

.lap 2:00

{ .freestyle }

.segment (0, 3:30)

{ }

.segment (4:30, 6:30)

{ }

.segment (8:30, 11:00)

{ }

.lap 6:30

{ .freestyle }

.lap 3:00

{ .butterfly }

Page 76: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Workout Request Pause/Resume

New gesture for pausing and resuming workouts

NEW

Page 77: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Workout Request Pause/Resume

New gesture for pausing and resuming workouts

Quick press of the Digital Crown and side button

NEW

Page 78: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Workout Request Pause/Resume

New gesture for pausing and resuming workouts

Quick press of the Digital Crown and side button

Does work in water lock

NEW

Page 79: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Workout Request Pause/Resume

New gesture for pausing and resuming workouts

Quick press of the Digital Crown and side button

Does work in water lock

Handle in your workout session delegate

NEW

Page 80: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

User

HealthKit

Your app

Page 81: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

User

HealthKit

Your app

Presses Digital Crown and side button

Page 82: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

User

HealthKit

Your app

Presses Digital Crown and side button

Generates pauseOrResumeRequest

Page 83: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

User

HealthKit

Your app

Presses Digital Crown and side button

Generates pauseOrResumeRequest

Receives request event in workout session delegate

Page 84: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

User

HealthKit

Your app

Presses Digital Crown and side button

Generates pauseOrResumeRequest

Receives request event in workout session delegate

Based on state, calls pause or resume on health store

Page 85: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

User

HealthKit

Your app

Presses Digital Crown and side button

Generates pauseOrResumeRequest

Receives request event in workout session delegate

Based on state, calls pause or resume on health store

Generates pause event or resume event

Page 86: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

User

HealthKit

Your app

Presses Digital Crown and side button

Generates pauseOrResumeRequest

Receives request event in workout session delegate

Based on state, calls pause or resume on health store

Generates pause event or resume event

Receives pause event or resume event in delegate

Page 87: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

•Workout Routes

Page 88: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for
Page 89: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Reading Workout Routes New data type

NEW

HKWorkoutRouteType

Page 90: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Reading Workout Routes New data type

NEW

HKWorkoutRouteType

Requires additional authorization

Page 91: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Reading Workout Routes New data type

NEW

HKWorkoutRouteType

Requires additional authorization

Modeled as an array of CLLocations

Page 92: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

NEWReading Workout Routes New data type

HKWorkoutRouteType

Requires additional authorization

Modeled as an array of CLLocations

Datasets can be large

Page 93: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

NEWReading Workout Routes New data type

HKWorkoutRouteType

Requires additional authorization

Modeled as an array of CLLocations

Datasets can be large • New HKWorkoutRouteQuery

Page 94: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Reading Workout Routes New data type

NEW

HKWorkoutRouteType

Requires additional authorization

Modeled as an array of CLLocations

Datasets can be large • New HKWorkoutRouteQuery • Returns location data in batches

Page 95: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Step 1: Query for samples of type HKWorkoutRoute associated to your workout

Page 96: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Step 1: Query for samples of type HKWorkoutRoute associated to your workout let workoutRouteType = HKSeriesType.workoutRoute() let workoutPredicate = HKQuery.predicateForObjects(from: workout)

Page 97: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Step 1: Query for samples of type HKWorkoutRoute associated to your workout let workoutRouteType = HKSeriesType.workoutRoute() let workoutPredicate = HKQuery.predicateForObjects(from: workout) let workoutRoutesQuery = HKSampleQuery(sampleType: workoutRouteType, predicate: workoutPredicate, limit: HKObjectQueryNoLimit, sortDescriptors: nil) { (query, samples, error) in

}

Page 98: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Step 1: Query for samples of type HKWorkoutRoute associated to your workout let workoutRouteType = HKSeriesType.workoutRoute() let workoutPredicate = HKQuery.predicateForObjects(from: workout) let workoutRoutesQuery = HKSampleQuery(sampleType: workoutRouteType, predicate: workoutPredicate, limit: HKObjectQueryNoLimit, sortDescriptors: nil) { (query, samples, error) in guard let routeSamples = samples as? [HKWorkoutRoute] else { return }

}

Page 99: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Step 1: Query for samples of type HKWorkoutRoute associated to your workout let workoutRouteType = HKSeriesType.workoutRoute() let workoutPredicate = HKQuery.predicateForObjects(from: workout) let workoutRoutesQuery = HKSampleQuery(sampleType: workoutRouteType, predicate: workoutPredicate, limit: HKObjectQueryNoLimit, sortDescriptors: nil) { (query, samples, error) in guard let routeSamples = samples as? [HKWorkoutRoute] else { return }

// Step 2: Query for location data from the routes for routeSample in routeSamples {

} }

Page 100: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Step 1: Query for samples of type HKWorkoutRoute associated to your workout let workoutRouteType = HKSeriesType.workoutRoute() let workoutPredicate = HKQuery.predicateForObjects(from: workout) let workoutRoutesQuery = HKSampleQuery(sampleType: workoutRouteType, predicate: workoutPredicate, limit: HKObjectQueryNoLimit, sortDescriptors: nil) { (query, samples, error) in guard let routeSamples = samples as? [HKWorkoutRoute] else { return }

// Step 2: Query for location data from the routes for routeSample in routeSamples { let locationQuery = HKWorkoutRouteQuery(route: routeSample) { (routeQuery, locations, done, error) in

} } }

Page 101: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Step 1: Query for samples of type HKWorkoutRoute associated to your workout let workoutRouteType = HKSeriesType.workoutRoute() let workoutPredicate = HKQuery.predicateForObjects(from: workout) let workoutRoutesQuery = HKSampleQuery(sampleType: workoutRouteType, predicate: workoutPredicate, limit: HKObjectQueryNoLimit, sortDescriptors: nil) { (query, samples, error) in guard let routeSamples = samples as? [HKWorkoutRoute] else { return }

// Step 2: Query for location data from the routes for routeSample in routeSamples { let locationQuery = HKWorkoutRouteQuery(route: routeSample) { (routeQuery, locations, done, error) in self.addLocationsToMapDisplay(locations) } } }

Page 102: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Step 1: Query for samples of type HKWorkoutRoute associated to your workout let workoutRouteType = HKSeriesType.workoutRoute() let workoutPredicate = HKQuery.predicateForObjects(from: workout) let workoutRoutesQuery = HKSampleQuery(sampleType: workoutRouteType, predicate: workoutPredicate, limit: HKObjectQueryNoLimit, sortDescriptors: nil) { (query, samples, error) in guard let routeSamples = samples as? [HKWorkoutRoute] else { return }

// Step 2: Query for location data from the routes for routeSample in routeSamples { let locationQuery = HKWorkoutRouteQuery(route: routeSample) { (routeQuery, locations, done, error) in self.addLocationsToMapDisplay(locations) } self.healthStore.execute(locationQuery) } } self.healthStore.execute(workoutRoutesQuery)

Page 103: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Building and Saving Workout Routes

Builder model—HKWorkoutRouteBuilder

NEW

Page 104: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Building and Saving Workout Routes

Builder model—HKWorkoutRouteBuilder

Location data is added asynchronously

NEW

Page 105: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Building and Saving Workout Routes

Builder model—HKWorkoutRouteBuilder

Location data is added asynchronously

Data is sorted by date when the series is finished

NEW

Page 106: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Building and Saving Workout Routes

Builder model—HKWorkoutRouteBuilder

Location data is added asynchronously

Data is sorted by date when the series is finished

The workout must be saved before the route

NEW

Page 107: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for
Page 108: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Create workout route builder

Page 109: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Create workout route builder

Page 110: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Create workout route builder

Start workout session

Page 111: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Create workout route builder

Start workout session

Page 112: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Create workout route builder

Start workout session

Active Workout

Page 113: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Create workout route builder

Start workout session

Active Workout

Page 114: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Create workout route builder

Start workout session

Active Workout

Observe location data

Page 115: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Create workout route builder

Add locations to builder

Start workout session

Active Workout

Observe location data

Page 116: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

End session, save workout

Create workout route builder

Add locations to builder

Start workout session

Active Workout

Observe location data

Page 117: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

End session, save workout

Create workout route builder

Add locations to builder

Start workout session

Active Workout

Finishworkout route

Observe location data

Page 118: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Step 1: Create a route builder and add locations let builder = HKWorkoutRouteBuilder(healthStore: healthStore, device: nil)

Page 119: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Step 1: Create a route builder and add locations let builder = HKWorkoutRouteBuilder(healthStore: healthStore, device: nil)

// Step 2: Add locations as the workout is ongoing let locations: [CLLocation] = self.fetchRecentLocations() builder.insertRouteData(locations) { (success, error) in // Handle errors... }

Page 120: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Step 1: Create a route builder and add locations let builder = HKWorkoutRouteBuilder(healthStore: healthStore, device: nil)

// Step 2: Add locations as the workout is ongoing let locations: [CLLocation] = self.fetchRecentLocations() builder.insertRouteData(locations) { (success, error) in // Handle errors... }

// Step 3: After the workout is saved, save the route data builder.finishRoute(with: workout, metadata: nil) { (workoutRoute, error) in // Handle errors... }

Page 121: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

•Workout Route Demo •Incorporating routes into Speedy Sloth

Page 122: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Michael Ozeryansky, iOS Software Engineer

•HKObject Sync Identifiers

Page 123: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

HKObject Sync Identifiers Identifiers and versioning

public let HKMetadataKeySyncIdentifier: Stringpublic let HKMetadataKeySyncVersion: String

NEW

Page 124: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

HKObject Sync Identifiers Identifiers and versioning

public let HKMetadataKeySyncIdentifier: Stringpublic let HKMetadataKeySyncVersion: String

NEW

Identifier can be any String

Page 125: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

HKObject Sync Identifiers Identifiers and versioning

public let HKMetadataKeySyncIdentifier: Stringpublic let HKMetadataKeySyncVersion: String

NEW

Identifier can be any String

Version can be any Number

Page 126: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

HKObject Sync Identifiers Identifiers and versioning

public let HKMetadataKeySyncIdentifier: Stringpublic let HKMetadataKeySyncVersion: String

NEW

Identifier can be any String

Version can be any Number

Use both keys together when saving an HKObject

Page 127: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

HKObject Sync Identifiers Identifiers and versioning

public let HKMetadataKeySyncIdentifier: Stringpublic let HKMetadataKeySyncVersion: String

NEW

Identifier can be any String

Version can be any Number

Use both keys together when saving an HKObject

Restricted to your source

Page 128: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

HKObject Sync Identifiers Identifiers and versioning

NEW

Page 129: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

HKObject Sync Identifiers Identifiers and versioning

Sample uniqueness

NEW

Page 130: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

HKObject Sync Identifiers Identifiers and versioning

Sample uniqueness

Local versioning

NEW

Page 131: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

HKObject Sync Identifiers Identifiers and versioning

Sample uniqueness

Local versioning

Transaction safe

NEW

Page 132: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

HKObject Sync Identifiers Identifiers and versioning

Sample uniqueness

Local versioning

Transaction safe

Relationships are maintained

NEW

Page 133: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for
Page 134: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V1

Page 135: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V1

Page 136: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V1

V1 Upload

Page 137: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V1

V1

Page 138: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V1

V1

Sync

Page 139: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V1

V1

V1

Sync

Page 140: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V1V1

V1

Page 141: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V1

V2

V1

Processing

Page 142: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V1

V2

V1

V2

Page 143: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V1

V2Download

V1

V2

Page 144: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V1

V2

V1

V2

Page 145: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V1

V2

V1

V2

Delete and add

Page 146: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V1V2

V2

Page 147: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V1V2

V2

Sync

Page 148: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V2

V2

Sync

V1

V2

Page 149: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V2

V2

Sync V1

V2

Delete and add

Page 150: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V2V2

V2

V2

Page 151: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V2V2

V2 Download

V2

Page 152: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V2V2

V2

Page 153: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

V2V2

V2

Page 154: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

•Demo •Updating samples using sync identifiers

Page 155: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

•Sample Source Information •Understanding the context and fidelity of HealthKit data

Page 156: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

open class HKSourceRevision : NSObject, NSSecureCoding, NSCopying {

open var source: HKSource { get } open var version: NSString? { get } o pen var operatingSystemVersion: OperatingSystemVersion { get } // e.g. {4, 0, 0} }

New Properties on HKSourceRevision Operating system version and product type

Page 157: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

open class HKSourceRevision : NSObject, NSSecureCoding, NSCopying {

open var source: HKSource { get } open var version: NSString? { get } open var productType: String? { get } // e.g. “watch2,4”

}

NEWNew Properties on HKSourceRevision Operating system version and product type

Page 158: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

open class HKSourceRevision : NSObject, NSSecureCoding, NSCopying {

open var source: HKSource { get } open var version: NSString? { get } open var productType: String? { get } // e.g. “watch2,4” open var operatingSystemVersion: OperatingSystemVersion { get } // e.g. {4, 0, 0} }

NEWNew Properties on HKSourceRevision Operating system version and product type

Page 159: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

open class HKSourceRevision : NSObject, NSSecureCoding, NSCopying {

open var source: HKSource { get } open var version: NSString? { get } open var productType: String? { get } // e.g. “watch2,4” open var operatingSystemVersion: OperatingSystemVersion { get } // e.g. {4, 0, 0} }

public let HKSourceRevisionAnyVersion: String public let HKSourceRevisionAnyProductType: String public let HKSourceRevisionAnyOperatingSystem: OperatingSystemVersion

NEWNew Properties on HKSourceRevision Operating system version and product type

Page 160: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

•Supporting Diabetes Management

Page 161: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Supporting Diabetes ManagementNEW

What’s New in Core Bluetooth Grand Ballroom B Thursday 11:00AM

Page 162: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Supporting Diabetes Management

Blood glucose meal time

NEW

What’s New in Core Bluetooth Grand Ballroom B Thursday 11:00AM

Page 163: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Supporting Diabetes Management

Blood glucose meal time

Insulin support

NEW

What’s New in Core Bluetooth Grand Ballroom B Thursday 11:00AM

Page 164: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Supporting Diabetes Management

Blood glucose meal time

Insulin support

CoreBluetooth in watchOS 4

NEW

What’s New in Core Bluetooth Grand Ballroom B Thursday 11:00AM

Page 165: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Supporting Diabetes Management Blood glucose meal time

NEW

Page 166: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Supporting Diabetes Management Blood glucose meal time

NEW

public let HKMetadataKeyBloodGlucoseMealTime: String

Page 167: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Supporting Diabetes Management Blood glucose meal time

NEW

public let HKMetadataKeyBloodGlucoseMealTime: String

public enum HKBloodGlucoseMealTime: Int { case preprandial case postprandial}

Page 168: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Supporting Diabetes Management Blood glucose meal time

NEW

public let HKMetadataKeyBloodGlucoseMealTime: String

public enum HKBloodGlucoseMealTime: Int { case preprandial case postprandial}

Time relative to a meal

Page 169: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Supporting Diabetes Management Insulin delivery

NEW

Page 170: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Supporting Diabetes Management Insulin delivery

NEW

Page 171: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

public static let insulinDelivery: HKQuantityTypeIdentifier

Supporting Diabetes Management Insulin delivery

NEW

Page 172: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

public static let insulinDelivery: HKQuantityTypeIdentifier

public let HKMetadataKeyInsulinDeliveryReason: String

Supporting Diabetes Management Insulin delivery

NEW

Page 173: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

public static let insulinDelivery: HKQuantityTypeIdentifier

public let HKMetadataKeyInsulinDeliveryReason: String

public enum HKInsulinDeliveryReason : Int { case basal case bolus}

Supporting Diabetes Management Insulin delivery

NEW

Page 174: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

public static let insulinDelivery: HKQuantityTypeIdentifier

public let HKMetadataKeyInsulinDeliveryReason: String

public enum HKInsulinDeliveryReason : Int { case basal case bolus}

Insulin that has been delivered

Supporting Diabetes Management Insulin delivery

NEW

Page 175: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

public static let insulinDelivery: HKQuantityTypeIdentifier

public let HKMetadataKeyInsulinDeliveryReason: String

public enum HKInsulinDeliveryReason : Int { case basal case bolus}

Insulin that has been delivered

International unit

Supporting Diabetes Management Insulin delivery

NEW

Page 176: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

extension HKUnit { open class func internationalUnit() -> Self }

Supporting Diabetes Management International unit

NEW

Page 177: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

extension HKUnit { open class func internationalUnit() -> Self }

Supporting Diabetes Management International unit

NEW

Biological effectiveness

Page 178: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

extension HKUnit { open class func internationalUnit() -> Self }

Supporting Diabetes Management International unit

NEW

Biological effectiveness

Cannot be converted to other units

Page 179: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Add Basal Insulin Sample From an Insulin Pump

Page 180: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Add Basal Insulin Sample From an Insulin Pump // Step 1: Create an insulin delivery quantity type let quantityType = HKQuantityType.quantityType(forIdentifier: .insulinDelivery)!

Page 181: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Add Basal Insulin Sample From an Insulin Pump // Step 1: Create an insulin delivery quantity type let quantityType = HKQuantityType.quantityType(forIdentifier: .insulinDelivery)!

// Step 2: Create a quantity of 0.825 units let quantity = HKQuantity(unit: .internationalUnit(), doubleValue: 0.825)

Page 182: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Add Basal Insulin Sample From an Insulin Pump // Step 3: Create a quantity sample let insulinSample = HKQuantitySample( type: quantityType, quantity: quantity, start: pumpDeliveryStartDate, end: pumpDeliveryEndDate, metadata: [ ])

Page 183: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Add Basal Insulin Sample From an Insulin Pump // Step 3: Create a quantity sample let insulinSample = HKQuantitySample( type: quantityType, quantity: quantity, start: pumpDeliveryStartDate, end: pumpDeliveryEndDate, metadata: [ HKMetadataKeyInsulinDeliveryReason: HKInsulinDeliveryReason.basal.rawValue ])

Page 184: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Add Basal Insulin Sample From an Insulin Pump // Step 3: Create a quantity sample let insulinSample = HKQuantitySample( type: quantityType, quantity: quantity, start: pumpDeliveryStartDate, end: pumpDeliveryEndDate, metadata: [ HKMetadataKeyInsulinDeliveryReason: HKInsulinDeliveryReason.basal.rawValue ])

// Step 4: Save the new samplehealthStore.save(insulinSample) { success, error in }

Page 185: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Statistics Query for Basal Samples

Page 186: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Statistics Query for Basal Samples

// Step 1: Setup the querylet predicate = HKQuery.predicateForObjects(withMetadataKey: HKMetadataKeyInsulinDeliveryReason, allowedValues:

[HKInsulinDeliveryReason.basal.rawValue])

Page 187: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Statistics Query for Basal Samples

// Step 1: Setup the querylet predicate = HKQuery.predicateForObjects(withMetadataKey: HKMetadataKeyInsulinDeliveryReason, allowedValues:

[HKInsulinDeliveryReason.basal.rawValue]) let quantityType = HKQuantityType.quantityType(forIdentifier: .insulinDelivery)!

Page 188: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Statistics Query for Basal Samples

// Step 1: Setup the querylet predicate = HKQuery.predicateForObjects(withMetadataKey: HKMetadataKeyInsulinDeliveryReason, allowedValues:

[HKInsulinDeliveryReason.basal.rawValue]) let quantityType = HKQuantityType.quantityType(forIdentifier: .insulinDelivery)!

let query = HKStatisticsCollectionQuery(quantityType: quantityType, quantitySamplePredicate: predicate, options: anchorDate: intervalComponents: )

Page 189: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Statistics Query for Basal Samples

// Step 1: Setup the querylet predicate = HKQuery.predicateForObjects(withMetadataKey: HKMetadataKeyInsulinDeliveryReason, allowedValues:

[HKInsulinDeliveryReason.basal.rawValue]) let quantityType = HKQuantityType.quantityType(forIdentifier: .insulinDelivery)!

let query = HKStatisticsCollectionQuery(quantityType: quantityType, quantitySamplePredicate: predicate, options: [.cumulativeSum, .separateBySource], anchorDate: intervalComponents: )

Page 190: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Statistics Query for Basal Samples

// Step 1: Setup the querylet predicate = HKQuery.predicateForObjects(withMetadataKey: HKMetadataKeyInsulinDeliveryReason, allowedValues:

[HKInsulinDeliveryReason.basal.rawValue]) let quantityType = HKQuantityType.quantityType(forIdentifier: .insulinDelivery)!

let query = HKStatisticsCollectionQuery(quantityType: quantityType, quantitySamplePredicate: predicate, options: [.cumulativeSum, .separateBySource], anchorDate: Date.distantPast, intervalComponents: )

Page 191: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Statistics Query for Basal Samples

// Step 1: Setup the querylet predicate = HKQuery.predicateForObjects(withMetadataKey: HKMetadataKeyInsulinDeliveryReason, allowedValues:

[HKInsulinDeliveryReason.basal.rawValue]) let quantityType = HKQuantityType.quantityType(forIdentifier: .insulinDelivery)!

let query = HKStatisticsCollectionQuery(quantityType: quantityType, quantitySamplePredicate: predicate, options: [.cumulativeSum, .separateBySource], anchorDate: Date.distantPast, intervalComponents: DateComponents(hour: 1))

Page 192: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Statistics Query for Basal Samples

// Step 2: Set the results handler query.initialResultsHandler = { query, results, error in // Process statistics }

Page 193: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

// Statistics Query for Basal Samples

// Step 2: Set the results handler query.initialResultsHandler = { query, results, error in // Process statistics }

// Step 3: Execute the query healthStore.execute(query)

Page 194: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Summary

Expand reach with new data types

Page 195: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Summary

Expand reach with new data types

Build engaging workout experiences

Page 196: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Summary

Expand reach with new data types

Build engaging workout experiences

Prevent data duplication with sync identifiers

Page 197: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Summary

Expand reach with new data types

Build engaging workout experiences

Prevent data duplication with sync identifiers

Support users managing diabetes

Page 198: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

More Informationhttps://developer.apple.com/wwdc17/221

Page 199: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Related Sessions

Creating Immersive Apps with Core Motion Grand Ballroom B Tuesday 4:10PM

What’s New in Core Bluetooth Grand Ballroom B Thursday 11:00AM

What’s New in Location Technologies Executive Ballroom Thursday 3:10PM

What’s New in CareKit and ResearchKit Grand Ballroom A Thursday 5:10PM

Page 200: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for

Labs

Health, Fitness, and Research Get-Together Grand Ballroom A Wed 6:30PM–7:45PM

HealthKit Lab Technology Lab H Thur 9:00AM–12:00PM

WatchConnectivity and WatchKit Lab Technology Lab B Fri 9:00AM–11:00AM

ResearchKit and CareKit Lab Technology Lab H Fri 11:00AM–1:00PM

Page 201: •What’s New in Health - Apple Developer · 2017-06-08 · Alexa VanHattum, iOS Software Engineer Michael Ozeryansky, iOS Software Engineer •What’s New in Health ... Used for