Skip to content

Commit

Permalink
Update WorkoutTracking.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
cagnulein committed Jan 4, 2024
1 parent d28acf3 commit fb3777b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/ios/WorkoutTracking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ protocol WorkoutTrackingProtocol {
@objc class WorkoutTracking: NSObject {
static let shared = WorkoutTracking()
public static var lastDateMetric = Date()
public static var distance = Double()
public static var kcal = Double()
var sport: Int = 0
let healthStore = HKHealthStore()
let configuration = HKWorkoutConfiguration()
var workoutBuilder: HKWorkoutBuilder!
var workoutInProgress: false
var workoutInProgress: Bool = false

weak var delegate: WorkoutTrackingDelegate?

Expand Down Expand Up @@ -134,8 +136,9 @@ extension WorkoutTracking: WorkoutTrackingProtocol {
}

@objc func startWorkOut() {
if(workoutInProgress)
if(workoutInProgress) {
return;
}
workoutInProgress = true;
WorkoutTracking.lastDateMetric = Date()
print("Start workout")
Expand Down Expand Up @@ -238,6 +241,10 @@ extension WorkoutTracking: WorkoutTrackingProtocol {
@objc func addMetrics(power: Double, cadence: Double, speed: Double) {
print("GET DATA: \(Date())")

if(workoutInProgress == false) {
startWorkOut()
}

if(sport == 0) {
if #available(watchOSApplicationExtension 10.0, *) {
let wattPerInterval = HKQuantity(unit: HKUnit.watt(),
Expand Down Expand Up @@ -344,7 +351,7 @@ extension WorkoutTracking: WorkoutTrackingProtocol {
} else if(sport == 2) {
if #available(watchOSApplicationExtension 10.0, *) {
let speedPerInterval = HKQuantity(unit: HKUnit.meter().unitDivided(by: HKUnit.second()),
doubleValue: WorkoutTracking.speed * 0.277778)
doubleValue: speed * 0.277778)

guard let speedType = HKQuantityType.quantityType(
forIdentifier: .walkingSpeed) else {
Expand Down

0 comments on commit fb3777b

Please sign in to comment.