complete then get health data on completion screen
This commit is contained in:
@@ -50,7 +50,7 @@ class BridgeModule: NSObject, ObservableObject {
|
||||
// workoutEndDate fills out WatchPackageModel.workoutEndDate which
|
||||
// tells the watch app to stop the workout
|
||||
public private(set) var workoutEndDate: Date?
|
||||
public private(set) var healthKitUUID: UUID?
|
||||
@Published public private(set) var healthKitUUID: UUID?
|
||||
|
||||
var audioPlayer: AVAudioPlayer?
|
||||
var avPlayer: AVPlayer?
|
||||
@@ -101,7 +101,6 @@ class BridgeModule: NSObject, ObservableObject {
|
||||
self.workoutStartDate = nil
|
||||
self.workoutEndDate = nil
|
||||
}
|
||||
sendResetToWatch()
|
||||
}
|
||||
|
||||
private func startWorkoutTimer() {
|
||||
@@ -207,12 +206,9 @@ class BridgeModule: NSObject, ObservableObject {
|
||||
self.isInWorkout = false
|
||||
|
||||
workoutEndDate = Date()
|
||||
|
||||
//if connected to watch
|
||||
if WCSession.default.isReachable {
|
||||
self.sendWorkoutCompleteToWatch()
|
||||
} else {
|
||||
completedWorkout?()
|
||||
if let completedWorkout = completedWorkout {
|
||||
completedWorkout()
|
||||
self.completedWorkout = nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,9 +274,11 @@ extension BridgeModule: WCSessionDelegate {
|
||||
}
|
||||
|
||||
func sendWorkoutCompleteToWatch() {
|
||||
let model = PhoneToWatchActions.endWorkout
|
||||
let data = try! JSONEncoder().encode(model)
|
||||
send(data)
|
||||
if WCSession.default.isReachable {
|
||||
let model = PhoneToWatchActions.endWorkout
|
||||
let data = try! JSONEncoder().encode(model)
|
||||
send(data)
|
||||
}
|
||||
}
|
||||
|
||||
func sendCurrentExerciseToWatch() {
|
||||
@@ -313,9 +311,10 @@ extension BridgeModule: WCSessionDelegate {
|
||||
nextExercise()
|
||||
playFinished()
|
||||
case .workoutComplete(let data):
|
||||
let model = try! JSONDecoder().decode(WatchFinishWorkoutModel.self, from: data)
|
||||
healthKitUUID = model.healthKitUUID
|
||||
completedWorkout?()
|
||||
DispatchQueue.main.async {
|
||||
let model = try! JSONDecoder().decode(WatchFinishWorkoutModel.self, from: data)
|
||||
self.healthKitUUID = model.healthKitUUID
|
||||
}
|
||||
case .restartExercise:
|
||||
restartExercise()
|
||||
case .previousExercise:
|
||||
|
||||
Reference in New Issue
Block a user