Bläddra i källkod

Request state upate when app launches

polscm32 aka Marvout 1 år sedan
förälder
incheckning
e19337a575

+ 0 - 10
Trio Watch App Extension/Views/TrioMainWatchView.swift

@@ -59,16 +59,6 @@ struct TrioMainWatchView: View {
                     updateRotation(for: newTrend)
                     updateRotation(for: newTrend)
                 }
                 }
             }
             }
-            .onAppear {
-                // request fresh data from watch
-                state.requestWatchStateUpdate()
-
-                // reset input amounts
-                state.bolusAmount = 0
-                state.carbsAmount = 0
-                // reset auth progress
-                state.confirmationProgress = 0
-            }
             .toolbar {
             .toolbar {
                 ToolbarItem(placement: .topBarLeading) {
                 ToolbarItem(placement: .topBarLeading) {
                     HStack {
                     HStack {

+ 14 - 4
Trio Watch App Extension/WatchState.swift

@@ -443,16 +443,16 @@ import WatchConnectivity
                 print("⌚️ Watch session activation failed: \(error.localizedDescription)")
                 print("⌚️ Watch session activation failed: \(error.localizedDescription)")
                 return
                 return
             }
             }
-            
+
             // the order here is probably not perfect and needsto be re-arranged
             // the order here is probably not perfect and needsto be re-arranged
             if activationState == .activated {
             if activationState == .activated {
                 self.requestWatchStateUpdate()
                 self.requestWatchStateUpdate()
             }
             }
 
 
             print("⌚️ Watch session activated with state: \(activationState.rawValue)")
             print("⌚️ Watch session activated with state: \(activationState.rawValue)")
-            
+
             self.isReachable = session.isReachable
             self.isReachable = session.isReachable
-            
+
             print("⌚️ Watch isReachable after activation: \(session.isReachable)")
             print("⌚️ Watch isReachable after activation: \(session.isReachable)")
         }
         }
     }
     }
@@ -483,8 +483,18 @@ import WatchConnectivity
     /// Updates the local reachability status
     /// Updates the local reachability status
     func sessionReachabilityDidChange(_ session: WCSession) {
     func sessionReachabilityDidChange(_ session: WCSession) {
         DispatchQueue.main.async {
         DispatchQueue.main.async {
-            self.isReachable = session.isReachable
             print("⌚️ Watch reachability changed: \(session.isReachable)")
             print("⌚️ Watch reachability changed: \(session.isReachable)")
+
+            if session.isReachable {
+                // request fresh data from watch
+                self.requestWatchStateUpdate()
+
+                // reset input amounts
+                self.bolusAmount = 0
+                self.carbsAmount = 0
+                // reset auth progress
+                self.confirmationProgress = 0
+            }
         }
         }
     }
     }
 }
 }