This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Create to store in a workoutTimestamps for graphs and statistics
Laps and Markers NEW
HKWorkoutEventType.lap
HKWorkoutEventType.marker
Create to store in a workoutTimestamps for graphs and statisticsLaps for equal distance partitions
Laps and Markers NEW
HKWorkoutEventType.lap
HKWorkoutEventType.marker
Create to store in a workoutTimestamps for graphs and statisticsLaps for equal distance partitionsMarkers for arbitrary points
Laps and Markers NEW
HKWorkoutEventType.lap
HKWorkoutEventType.marker
Create to store in a workoutTimestamps for graphs and statisticsLaps for equal distance partitionsMarkers for arbitrary points
Laps and Markers NEW
HKWorkoutEventType.lap
HKWorkoutEventType.marker
Pausing and Resuming
Pausing and Resuming
Users stop their activity
Pausing and Resuming
Users stop their activityPause workouts to save power and space
Pausing and Resuming
Users stop their activityPause workouts to save power and spaceIgnore data while paused
Pausing and Resuming
Users stop their activityPause workouts to save power and spaceIgnore data while pausedHealthKit responds with pause/resume events
Pausing and Resuming
Users stop their activityPause workouts to save power and spaceIgnore data while pausedHealthKit responds with pause/resume eventsAfter pause event, you will stop receiving new events
Pausing and Resuming NEW
class HKHealthStore {
func pause(_ workoutSession: HKWorkoutSession)
func resume(_ workoutSession: HKWorkoutSession)
...
}
Pausing and Resuming NEW
class HKHealthStore {
func pause(_ workoutSession: HKWorkoutSession)
func resume(_ workoutSession: HKWorkoutSession)
...
}
HKWorkoutEventType.pause
HKWorkoutEventType.resume
Motion Events for Running Workouts NEW
Motion Events for Running Workouts NEW
HKWorkoutEventType.motionPaused
HKWorkoutEventType.motionResumed
Motion Events for Running Workouts
Watch detects when motion pauses or resumes
NEW
HKWorkoutEventType.motionPaused
HKWorkoutEventType.motionResumed
Motion Events for Running Workouts
Watch detects when motion pauses or resumesStop collecting data
NEW
HKWorkoutEventType.motionPaused
HKWorkoutEventType.motionResumed
Motion Events for Running Workouts
Watch detects when motion pauses or resumesStop collecting dataDon’t need to manual pause
NEW
HKWorkoutEventType.motionPaused
HKWorkoutEventType.motionResumed
Motion Events for Running Workouts
Watch detects when motion pauses or resumesStop collecting dataDon’t need to manual pause Only for HKWorkoutActivityTypeRunning
let workout = HKWorkout( activityType: config.activityType,
// Save Workout
let workout = HKWorkout(
start: startDate,
activityType: config.activityType,
// Save Workout
let workout = HKWorkout(
start: startDate,
end: endDate,
activityType: config.activityType,
// Save Workout
let workout = HKWorkout(
start: startDate,
end: endDate,
workoutEvents: events,
activityType: config.activityType,
// Save Workout
let workout = HKWorkout(
start: startDate,
end: endDate,
workoutEvents: events,
totalEnergyBurned: totalEnergyBurned,
activityType: config.activityType,
// Save Workout
let workout = HKWorkout(
start: startDate,
end: endDate,
workoutEvents: events,
totalEnergyBurned: totalEnergyBurned,
totalDistance: totalDistance,
activityType: config.activityType,
// Save Workout
let workout = HKWorkout(
start: startDate,
end: endDate,
workoutEvents: events,
totalEnergyBurned: totalEnergyBurned,
totalDistance: totalDistance,
metadata: [HKMetadataKeyIndoorWorkout: isIndoor])
activityType: config.activityType,
// Save Workout
let workout = HKWorkout(
start: startDate,
end: endDate,
workoutEvents: events,
totalEnergyBurned: totalEnergyBurned,
totalDistance: totalDistance,
metadata: [HKMetadataKeyIndoorWorkout: isIndoor])
healthStore.save(workout) { (success, error) in
// Workout saved
}
activityType: config.activityType,
Add Samples to Workout
Add Samples to Workout
Creates an association
Add Samples to Workout
Creates an associationQuery later for graphs
Add Samples to Workout
Creates an associationQuery later for graphsActivity Move ring credit
Add Samples to Workout
Creates an associationQuery later for graphsActivity Move ring creditMatch totals on HKWorkout
// Add Samples to Workout
healthStore.add(samples, to: workout) { (success, error) in
// Samples added
}
DemoSpeedySloth: Ending and Saving
Dash BrittainiOS Software Engineer
Workouts in iOS 10
Jorge MoriñigoiOS Software Engineer
Workouts in iOS 10
Workouts in iOS 10
Workout apps have parent iPhone application
Workouts in iOS 10
Workout apps have parent iPhone applicationWatchConnectivity for messaging when Apple Watch app is running
Workouts in iOS 10
Workout apps have parent iPhone applicationWatchConnectivity for messaging when Apple Watch app is runningBackground running
Workouts in iOS 10
Workout apps have parent iPhone applicationWatchConnectivity for messaging when Apple Watch app is runningBackground runningStart a workout from iPhone
Workouts in iOS 10
Workout apps have parent iPhone applicationWatchConnectivity for messaging when Apple Watch app is runningBackground runningStart a workout from iPhoneNo user intervention on Apple Watch
Workouts in iOS 10
HKWorkoutConfiguration
iPhone App
Workouts in iOS 10
HKWorkoutConfiguration
iPhone App Apple Watch App
Workouts in iOS 10
HKWorkoutConfigurationStart
HKWorkoutSession
iPhone App Apple Watch App
Workouts in iOS 10
HKWorkoutConfigurationStart
HKWorkoutSession
iPhone App Apple Watch App
<key>UIBackgroundModes</key>
<array>
<string>workout-processing</string>
</array>
var workoutConfiguration = HKWorkoutConfiguration()
workoutConfiguration.activityType = .running
workoutConfiguration.locationType = .outdoor
let workoutSession = HKWorkoutSession(configuration: workoutConfiguration)
workoutSession.delegate = self
healthStore.start(workoutSession)
// Starting Workout from iPhone
var workoutConfiguration = HKWorkoutConfiguration()
workoutConfiguration.activityType = .running
workoutConfiguration.locationType = .outdoor
let workoutSession = HKWorkoutSession(configuration: workoutConfiguration)
workoutSession.delegate = self
healthStore.start(workoutSession)
// Starting Workout from iPhone
var workoutConfiguration = HKWorkoutConfiguration()
workoutConfiguration.activityType = .running
workoutConfiguration.locationType = .outdoor
let workoutSession = HKWorkoutSession(configuration: workoutConfiguration)
workoutSession.delegate = self
healthStore.start(workoutSession)
// Starting Workout from iPhone
var workoutConfiguration = HKWorkoutConfiguration()
workoutConfiguration.activityType = .running
workoutConfiguration.locationType = .outdoor
let workoutSession = HKWorkoutSession(configuration: workoutConfiguration)
workoutSession.delegate = self
healthStore.start(workoutSession)
// Starting Workout from iPhone
var workoutConfiguration = HKWorkoutConfiguration()
workoutConfiguration.activityType = .running
workoutConfiguration.locationType = .outdoor
let workoutSession = HKWorkoutSession(configuration: workoutConfiguration)
workoutSession.delegate = self
healthStore.start(workoutSession)
// Apple Watch App
// Starting Workout from iPhone
// iPhone App
var workoutConfiguration = HKWorkoutConfiguration()
workoutConfiguration.activityType = .running
workoutConfiguration.locationType = .outdoor
// Starting Workout from iPhone
// iPhone App
var workoutConfiguration = HKWorkoutConfiguration()
workoutConfiguration.activityType = .running
workoutConfiguration.locationType = .outdoor
// Starting Workout from iPhone
}
if wcSession.activationState == .activated && wcSession.isWatchAppInstalled {
// iPhone App
var workoutConfiguration = HKWorkoutConfiguration()
workoutConfiguration.activityType = .running
workoutConfiguration.locationType = .outdoor
// Starting Workout from iPhone
}
if wcSession.activationState == .activated && wcSession.isWatchAppInstalled {
// iPhone App
var workoutConfiguration = HKWorkoutConfiguration()
workoutConfiguration.activityType = .running
workoutConfiguration.locationType = .outdoor
// Starting Workout from iPhone
}
if wcSession.activationState == .activated && wcSession.isWatchAppInstalled {
// iPhone App
healthStore.startWatchApp(with: workoutConfiguration) { (success, error) in
...
}
var workoutConfiguration = HKWorkoutConfiguration()
workoutConfiguration.activityType = .running
workoutConfiguration.locationType = .outdoor
// Starting Workout from iPhone
// iPhone App
if wcSession.activationState == .activated && wcSession.isWatchAppInstalled {
}
healthStore.startWatchApp(with: workoutConfiguration) { (success, error) in
...
}
var workoutConfiguration = HKWorkoutConfiguration()
workoutConfiguration.activityType = .running
workoutConfiguration.locationType = .outdoor
// Starting Workout from iPhone
// iPhone App
if wcSession.activationState == .activated && wcSession.isWatchAppInstalled {
}
// Starting Workout from iPhone
// Starting Workout from iPhone
let workoutSession = HKWorkoutSession(configuration: workoutConfiguration)
let workoutSession = HKWorkoutSession(configuration: workoutConfiguration)
workoutSession.delegate = self
healthStore.start(workoutSession)
}
// Apple Watch App
DemoSpeedySloth: iPhone App
Jorge MoriñigoiOS Software Engineer
Best Practices
Best Practices
Ensure Apple Watch app is functional when iPhone is unreachable
Best Practices
Ensure Apple Watch app is functional when iPhone is unreachable• Keep session running when losing connectivity
Best Practices
Ensure Apple Watch app is functional when iPhone is unreachable• Keep session running when losing connectivity• Use HealthKit distance when GPS is unavailable
Best Practices
Ensure Apple Watch app is functional when iPhone is unreachable• Keep session running when losing connectivity• Use HealthKit distance when GPS is unavailable
User should be able to begin workout on Apple Watch or iPhone
Best Practices
Ensure Apple Watch app is functional when iPhone is unreachable• Keep session running when losing connectivity• Use HealthKit distance when GPS is unavailable
User should be able to begin workout on Apple Watch or iPhoneDisplay workouts from other sources
Best Practices
Ensure Apple Watch app is functional when iPhone is unreachable• Keep session running when losing connectivity• Use HealthKit distance when GPS is unavailable
User should be able to begin workout on Apple Watch or iPhoneDisplay workouts from other sourcesDon’t display deleted workouts
Summary
Summary
Background running
Summary
Background runningContribute to Activity rings
Summary
Background runningContribute to Activity ringsStart workout from Apple Watch or iPhone