Procházet zdrojové kódy

Add few more logs, force flush to phone on specific errors

Deniz Cengiz před 1 rokem
rodič
revize
8cb8cac6c2

+ 2 - 2
Trio Watch App Extension/WatchLogger.swift

@@ -30,7 +30,7 @@ final class WatchLogger {
         return dateFormatter
     }
 
-    func log(_ message: String, function: String = #function, file: String = #fileID, line: Int = #line) {
+    func log(_ message: String, force: Bool = false, function: String = #function, file: String = #fileID, line: Int = #line) {
         let shortFile = (file as NSString).lastPathComponent
         let timestamp = dateFormatter.string(from: Date())
         let entry = "[\(timestamp)] [\(shortFile):\(line)] \(function) → \(message)"
@@ -41,7 +41,7 @@ final class WatchLogger {
         }
 
         print(entry)
-        flushIfNeeded(force: false)
+        flushIfNeeded(force: force)
     }
 
     func flushIfNeeded(force: Bool = false) {

+ 3 - 3
Trio Watch App Extension/WatchState.swift

@@ -137,7 +137,7 @@ import WatchConnectivity
     func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
         DispatchQueue.main.async {
             if let error = error {
-                WatchLogger.shared.log("⌚️ Watch session activation failed: \(error.localizedDescription)")
+                WatchLogger.shared.log("⌚️ Watch session activation failed: \(error.localizedDescription)", force: true)
                 return
             }
 
@@ -253,14 +253,14 @@ import WatchConnectivity
 
     func session(_: WCSession, didReceiveUserInfo userInfo: [String: Any] = [:]) {
         guard let snapshot = WatchStateSnapshot(from: userInfo) else {
-            print("⌚️ Invalid snapshot received")
+            WatchLogger.shared.log("⌚️ Invalid snapshot received", force: true)
             return
         }
 
         let lastProcessed = WatchStateSnapshot.loadLatestDateFromDisk()
 
         guard snapshot.date > lastProcessed else {
-            print("⌚️ Ignoring outdated or duplicate WatchState snapshot")
+            WatchLogger.shared.log("⌚️ Ignoring outdated or duplicate WatchState snapshot", force: true)
             return
         }