This commit is contained in:
Trey t
2023-07-03 21:47:51 -05:00
parent 85dfc0a931
commit 38be95ea76
7 changed files with 69 additions and 11 deletions

View File

@@ -8,6 +8,7 @@
import Foundation
import WatchConnectivity
import AVFoundation
import HealthKit
enum WatchActions: Codable {
case nextExercise
@@ -40,6 +41,8 @@ class BridgeModule: NSObject, ObservableObject {
public private(set) var totalCaloire: Float?
public private(set) var heartRates: [Int]?
var audioPlayer: AVAudioPlayer?
func start(workout: Workout) {
self.currentWorkout = workout
currentWorkoutRunTimeInSeconds = 0
@@ -52,11 +55,12 @@ class BridgeModule: NSObject, ObservableObject {
startWorkoutTimer()
workoutStartDate = Date()
isInWorkout = true
if WCSession.isSupported() {
WCSession.default.delegate = self
WCSession.default.activate()
}
}
func goToExerciseAt(index: Int) {
@@ -178,13 +182,37 @@ class BridgeModule: NSObject, ObservableObject {
func playBeep() {
#if os(iOS)
AudioServicesPlaySystemSound(SystemSoundID(1052))
if let path = Bundle.main.path(forResource: "short_beep", ofType: "m4a") {
do {
try AVAudioSession.sharedInstance().setCategory(.playback,
mode: .default,
options: [.mixWithOthers, .allowAirPlay])
try AVAudioSession.sharedInstance().setActive(true)
audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: path))
audioPlayer?.play()
} catch {
print("ERROR")
}
}
#endif
}
func playFinished() {
#if os(iOS)
AudioServicesPlaySystemSound(SystemSoundID(1070))
if let path = Bundle.main.path(forResource: "long_beep", ofType: "m4a") {
do {
try AVAudioSession.sharedInstance().setCategory(.playback,
mode: .default,
options: [.mixWithOthers, .allowAirPlay])
try AVAudioSession.sharedInstance().setActive(true)
audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: path))
audioPlayer?.play()
} catch {
print("ERROR")
}
}
#endif
}
}
@@ -221,6 +249,16 @@ extension BridgeModule: WCSessionDelegate {
print("inactive")
case .activated:
print("activated")
#if os(iOS)
let workoutConfiguration = HKWorkoutConfiguration()
workoutConfiguration.activityType = .traditionalStrengthTraining
workoutConfiguration.locationType = .indoor
if WCSession.isSupported(), WCSession.default.activationState == .activated, WCSession.default.isWatchAppInstalled {
HKHealthStore().startWatchApp(with: workoutConfiguration, completion: { (success, error) in
print(error.debugDescription)
})
}
#endif
}
}
#if os(iOS)

View File

@@ -89,7 +89,7 @@ struct ExtExerciseList: View {
HStack {
if i == currentExerciseIdx {
Image(systemName: "checkmark")
.font(Font.system(size: 75))
.font(Font.system(size: 55))
.scaledToFit()
.minimumScaleFactor(0.01)
.lineLimit(1)
@@ -97,7 +97,7 @@ struct ExtExerciseList: View {
}
Text(obj.exercise.name)
.font(Font.system(size: 75))
.font(Font.system(size: 55))
.scaledToFit()
.minimumScaleFactor(0.01)
.lineLimit(1)
@@ -151,14 +151,16 @@ struct ExtCountdownView: View {
.scaledToFit()
.minimumScaleFactor(0.01)
.lineLimit(1)
.padding([.leading, .trailing])
.padding(.leading)
.padding(.trailing, 100)
} else if let reps = currenExercise.reps {
Text("\(reps)")
.font(Font.system(size: 75))
.scaledToFit()
.minimumScaleFactor(0.01)
.lineLimit(1)
.padding([.leading, .trailing])
.padding(.leading)
.padding(.trailing, 100)
}
}
.frame(height: metrics.size.height * 0.5)

View File

@@ -2,9 +2,15 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.developer.healthkit</key>
<true/>
<key>com.apple.developer.healthkit.access</key>
<array/>
<key>com.apple.developer.healthkit.background-delivery</key>
<true/>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
</dict>
</plist>

BIN
Werkout_ios/long_beep.m4a Normal file

Binary file not shown.

BIN
Werkout_ios/short_beep.m4a Normal file

Binary file not shown.