瀏覽代碼

Merge pull request #499 from nightscout/live-activity-pushdata

marv-out 1 年之前
父節點
當前提交
1ff357098d
共有 1 個文件被更改,包括 7 次插入2 次删除
  1. 7 2
      Trio/Sources/Services/LiveActivity/LiveActivityManager.swift

+ 7 - 2
Trio/Sources/Services/LiveActivity/LiveActivityManager.swift

@@ -305,7 +305,10 @@ final class LiveActivityManager: Injectable, ObservableObject, SettingsObserver
         if let currentActivity = currentActivity {
             if currentActivity.needsRecreation(), UIApplication.shared.applicationState == .active {
                 await endActivity()
-                await pushUpdate(state)
+                Task { @MainActor in
+                    await self.pushUpdate(state)
+                }
+                return
             } else {
                 let content = ActivityContent(
                     state: state,
@@ -408,7 +411,9 @@ final class LiveActivityManager: Injectable, ObservableObject, SettingsObserver
             try? await Task.sleep(nanoseconds: 200_000_000) // 0.2s sleep
         }
 
-        await pushUpdate(contentState)
+        Task { @MainActor in
+            await self.pushUpdate(contentState)
+        }
         debug(.default, "Restarted Live Activity from LiveActivityIntent (via iOS Shortcut)")
     }
 }