Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Missing Updates for Non-Simulator Builds #26

Merged
merged 1 commit into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Sources/SpeziTimedWalkTest/TimedWalkTestViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ class TimedWalkTestViewModel {
func requestPedemoterAccess() {
#if !targetEnvironment(simulator)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn’t a better solution be to move as much code out of the if compiler directive? E.g. have additional code for simulator at the start of the method and return before we reach the code executed on the life device. CoreMotion compiles in the simulator it just doesn’t do anything.

In essence: don’t exclude code using compiler directives (as best as possible) only use them to add additional code special to the simulator.

guard CMPedometer.isStepCountingAvailable() else {
walkTestResponse = .failure(.unauthorized)
walkTestResponse = .failed(.unauthorized)
return
}

pedometer.queryPedometerData(from: .now, to: .now) { data, error in
if data != nil {
self.authorizationStatus = CMPedometer.authorizationStatus()
} else {
self.walkTestResponse = .failure(TimedWalkTestError(errorCode: (error as? NSError)?.code ?? -1))
self.walkTestResponse = .failed(TimedWalkTestError(errorCode: (error as? NSError)?.code ?? -1))
}
}
#else
Expand Down Expand Up @@ -81,7 +81,7 @@ class TimedWalkTestViewModel {
#if !targetEnvironment(simulator)
pedometer.queryPedometerData(from: walkTestStartDate, to: walkTestEndDate) { data, error in
if let data, let distance = data.distance?.doubleValue {
self.walkTestResponse = .success(
self.walkTestResponse = .completed(
TimedWalkTestResult(
stepCount: data.numberOfSteps.doubleValue,
distance: distance,
Expand All @@ -90,7 +90,7 @@ class TimedWalkTestViewModel {
)
)
} else {
self.walkTestResponse = .failure(TimedWalkTestError(errorCode: (error as? NSError)?.code ?? -1))
self.walkTestResponse = .failed(TimedWalkTestError(errorCode: (error as? NSError)?.code ?? -1))
}
}
#else
Expand Down
Loading