WIP
This commit is contained in:
@@ -54,6 +54,7 @@ class BridgeModule: NSObject, ObservableObject {
|
||||
|
||||
var audioPlayer: AVAudioPlayer?
|
||||
var avPlayer: AVPlayer?
|
||||
private let session: WCSession = WCSession.default
|
||||
|
||||
func start(workout: Workout) {
|
||||
currentExerciseInfo.complete = {
|
||||
@@ -73,8 +74,8 @@ class BridgeModule: NSObject, ObservableObject {
|
||||
isInWorkout = true
|
||||
|
||||
if WCSession.isSupported() {
|
||||
WCSession.default.delegate = self
|
||||
WCSession.default.activate()
|
||||
session.delegate = self
|
||||
session.activate()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -277,15 +278,19 @@ extension BridgeModule: WCSessionDelegate {
|
||||
func sendResetToWatch() {
|
||||
let watchModel = PhoneToWatchActions.reset
|
||||
let data = try! JSONEncoder().encode(watchModel)
|
||||
send(data)
|
||||
|
||||
// user transferUserInfo b/c its guranteed to reach
|
||||
// and end the workout
|
||||
self.session.transferUserInfo(["package": data])
|
||||
}
|
||||
|
||||
func sendWorkoutCompleteToWatch() {
|
||||
if WCSession.default.isReachable {
|
||||
let model = PhoneToWatchActions.endWorkout
|
||||
let data = try! JSONEncoder().encode(model)
|
||||
send(data)
|
||||
}
|
||||
let model = PhoneToWatchActions.endWorkout
|
||||
let data = try! JSONEncoder().encode(model)
|
||||
|
||||
// user transferUserInfo b/c its guranteed to reach
|
||||
// and end the workout
|
||||
self.session.transferUserInfo(["package": data])
|
||||
}
|
||||
|
||||
func sendCurrentExerciseToWatch() {
|
||||
@@ -349,12 +354,14 @@ extension BridgeModule: WCSessionDelegate {
|
||||
let workoutConfiguration = HKWorkoutConfiguration()
|
||||
workoutConfiguration.activityType = .functionalStrengthTraining
|
||||
workoutConfiguration.locationType = .indoor
|
||||
if WCSession.isSupported(), WCSession.default.activationState == .activated, WCSession.default.isWatchAppInstalled {
|
||||
if WCSession.isSupported(), session.activationState == .activated, session.isWatchAppInstalled {
|
||||
HKHealthStore().startWatchApp(with: workoutConfiguration, completion: { (success, error) in
|
||||
print(error.debugDescription)
|
||||
})
|
||||
}
|
||||
#endif
|
||||
@unknown default:
|
||||
print("default")
|
||||
}
|
||||
}
|
||||
#if os(iOS)
|
||||
@@ -367,19 +374,19 @@ extension BridgeModule: WCSessionDelegate {
|
||||
}
|
||||
#endif
|
||||
func send(_ data: Data) {
|
||||
guard WCSession.default.activationState == .activated else {
|
||||
guard session.activationState == .activated else {
|
||||
return
|
||||
}
|
||||
#if os(iOS)
|
||||
guard WCSession.default.isWatchAppInstalled else {
|
||||
guard session.isWatchAppInstalled else {
|
||||
return
|
||||
}
|
||||
#else
|
||||
guard WCSession.default.isCompanionAppInstalled else {
|
||||
guard session.isCompanionAppInstalled else {
|
||||
return
|
||||
}
|
||||
#endif
|
||||
WCSession.default.sendMessageData(data, replyHandler: nil) { error in
|
||||
session.sendMessageData(data, replyHandler: nil) { error in
|
||||
print("Cannot send message: \(String(describing: error))")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user