Преглед на файлове

resend after failed try when switching watchface

Robert преди 4 месеца
родител
ревизия
4bb803dbc6
променени са 1 файла, в които са добавени 14 реда и са изтрити 3 реда
  1. 14 3
      Trio/Sources/Services/WatchManager/GarminManager.swift

+ 14 - 3
Trio/Sources/Services/WatchManager/GarminManager.swift

@@ -893,21 +893,32 @@ final class BaseGarminManager: NSObject, GarminManager, Injectable {
     // MARK: - Helper: Sending Messages
     // MARK: - Helper: Sending Messages
 
 
     /// Sends a message to a given IQApp with optional progress and completion callbacks.
     /// Sends a message to a given IQApp with optional progress and completion callbacks.
+    /// Retries once after a short delay if the first attempt fails (SDK may need time after re-registration).
     /// - Parameters:
     /// - Parameters:
     ///   - msg: The data to send to the watch app.
     ///   - msg: The data to send to the watch app.
     ///   - app: The `IQApp` instance representing the watchface or data field.
     ///   - app: The `IQApp` instance representing the watchface or data field.
     ///   - appName: The display name of the app for logging.
     ///   - appName: The display name of the app for logging.
-    private func sendMessage(_ msg: Any, to app: IQApp, appName: String) {
+    ///   - isRetry: Whether this is a retry attempt (to prevent infinite retries).
+    private func sendMessage(_ msg: Any, to app: IQApp, appName: String, isRetry: Bool = false) {
         connectIQ?.sendMessage(
         connectIQ?.sendMessage(
             msg,
             msg,
             to: app,
             to: app,
             progress: { _, _ in },
             progress: { _, _ in },
-            completion: { result in
+            completion: { [weak self] result in
                 switch result {
                 switch result {
                 case .success:
                 case .success:
                     debug(.watchManager, "Garmin: Successfully sent to \(appName)")
                     debug(.watchManager, "Garmin: Successfully sent to \(appName)")
                 default:
                 default:
-                    debug(.watchManager, "Garmin: FAILED to send to \(appName)")
+                    if isRetry {
+                        debug(.watchManager, "Garmin: FAILED to send to \(appName) (retry also failed)")
+                    } else {
+                        debug(.watchManager, "Garmin: FAILED to send to \(appName) - will retry in 2s")
+                        // Retry after delay - SDK may need time after re-registration
+                        DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
+                            self?.debugGarmin("Garmin: Retrying send to \(appName)")
+                            self?.sendMessage(msg, to: app, appName: appName, isRetry: true)
+                        }
+                    }
                 }
                 }
             }
             }
         )
         )