diff --git a/Werkout_ios.xcodeproj/project.pbxproj b/Werkout_ios.xcodeproj/project.pbxproj index 88bf8f3..94d26e0 100644 --- a/Werkout_ios.xcodeproj/project.pbxproj +++ b/Werkout_ios.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 1C31C8842A53AE3E00350540 /* short_beep.m4a in Resources */ = {isa = PBXBuildFile; fileRef = 1C31C8822A53AE3E00350540 /* short_beep.m4a */; }; + 1C31C8852A53AE3E00350540 /* long_beep.m4a in Resources */ = {isa = PBXBuildFile; fileRef = 1C31C8832A53AE3E00350540 /* long_beep.m4a */; }; 1C485C832A489B9C00A6F896 /* CompletedWorkouts.json in Resources */ = {isa = PBXBuildFile; fileRef = 1C485C822A489B9C00A6F896 /* CompletedWorkouts.json */; }; 1C485C872A4915C400A6F896 /* CreateWorkoutItemPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C485C862A4915C400A6F896 /* CreateWorkoutItemPickerView.swift */; }; 1C485C8A2A492BB400A6F896 /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C485C892A492BB400A6F896 /* LoginView.swift */; }; @@ -102,6 +104,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 1C31C8822A53AE3E00350540 /* short_beep.m4a */ = {isa = PBXFileReference; lastKnownFileType = file; path = short_beep.m4a; sourceTree = ""; }; + 1C31C8832A53AE3E00350540 /* long_beep.m4a */ = {isa = PBXFileReference; lastKnownFileType = file; path = long_beep.m4a; sourceTree = ""; }; 1C485C822A489B9C00A6F896 /* CompletedWorkouts.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = CompletedWorkouts.json; sourceTree = ""; }; 1C485C862A4915C400A6F896 /* CreateWorkoutItemPickerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CreateWorkoutItemPickerView.swift; sourceTree = ""; }; 1C485C892A492BB400A6F896 /* LoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = ""; }; @@ -223,6 +227,8 @@ 1CF65A242A3972840042FFBD /* Werkout_ios */ = { isa = PBXGroup; children = ( + 1C31C8832A53AE3E00350540 /* long_beep.m4a */, + 1C31C8822A53AE3E00350540 /* short_beep.m4a */, 1CF65A552A3AA6800042FFBD /* Werkout-ios-Info.plist */, 1CF65A482A39FB910042FFBD /* JSON */, 1CF65A252A3972840042FFBD /* Werkout_iosApp.swift */, @@ -473,6 +479,7 @@ files = ( 1CF65A5F2A3BF5A60042FFBD /* Equipment.json in Resources */, 1C485C832A489B9C00A6F896 /* CompletedWorkouts.json in Resources */, + 1C31C8852A53AE3E00350540 /* long_beep.m4a in Resources */, 1CF65A4A2A39FBB10042FFBD /* WorkoutOne.json in Resources */, 1CF65A652A3BF6BE0042FFBD /* AllWorkouts.json in Resources */, 1CF65A332A3972850042FFBD /* Preview Assets.xcassets in Resources */, @@ -483,6 +490,7 @@ 1CF65A542A3A9AF30042FFBD /* Straight_Leg_Sit_Up.mp4 in Resources */, 1CF65A2F2A3972850042FFBD /* Assets.xcassets in Resources */, 1CF65A872A4400E10042FFBD /* ToDo in Resources */, + 1C31C8842A53AE3E00350540 /* short_beep.m4a in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -770,6 +778,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; CODE_SIGN_ENTITLEMENTS = "Werkout_watch Watch App/Werkout_watch Watch App.entitlements"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; @@ -804,6 +813,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; CODE_SIGN_ENTITLEMENTS = "Werkout_watch Watch App/Werkout_watch Watch App.entitlements"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; diff --git a/Werkout_ios/BridgeModule.swift b/Werkout_ios/BridgeModule.swift index 3dc99ad..c6ffbb2 100644 --- a/Werkout_ios/BridgeModule.swift +++ b/Werkout_ios/BridgeModule.swift @@ -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) diff --git a/Werkout_ios/Views/ExternalWorkoutDetailView.swift b/Werkout_ios/Views/ExternalWorkoutDetailView.swift index 2584772..78147e3 100644 --- a/Werkout_ios/Views/ExternalWorkoutDetailView.swift +++ b/Werkout_ios/Views/ExternalWorkoutDetailView.swift @@ -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) diff --git a/Werkout_ios/Werkout_ios.entitlements b/Werkout_ios/Werkout_ios.entitlements index f2ef3ae..73896b4 100644 --- a/Werkout_ios/Werkout_ios.entitlements +++ b/Werkout_ios/Werkout_ios.entitlements @@ -2,9 +2,15 @@ - com.apple.security.app-sandbox - - com.apple.security.files.user-selected.read-only - + com.apple.developer.healthkit + + com.apple.developer.healthkit.access + + com.apple.developer.healthkit.background-delivery + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + diff --git a/Werkout_ios/long_beep.m4a b/Werkout_ios/long_beep.m4a new file mode 100644 index 0000000..8528558 Binary files /dev/null and b/Werkout_ios/long_beep.m4a differ diff --git a/Werkout_ios/short_beep.m4a b/Werkout_ios/short_beep.m4a new file mode 100644 index 0000000..7046ea8 Binary files /dev/null and b/Werkout_ios/short_beep.m4a differ diff --git a/Werkout_watch Watch App/Werkout_watch Watch App.entitlements b/Werkout_watch Watch App/Werkout_watch Watch App.entitlements index 2ab14a2..dab226c 100644 --- a/Werkout_watch Watch App/Werkout_watch Watch App.entitlements +++ b/Werkout_watch Watch App/Werkout_watch Watch App.entitlements @@ -6,5 +6,7 @@ com.apple.developer.healthkit.access + com.apple.developer.healthkit.background-delivery +