فهرست منبع

Update bg task start and end to new helper util syntax

Deniz Cengiz 1 سال پیش
والد
کامیت
07ef0a40b5
1فایلهای تغییر یافته به همراه3 افزوده شده و 16 حذف شده
  1. 3 16
      Trio/Sources/Shortcuts/LiveActivity/RestartLiveActivityIntentRequest.swift

+ 3 - 16
Trio/Sources/Shortcuts/LiveActivity/RestartLiveActivityIntentRequest.swift

@@ -11,18 +11,9 @@ import UIKit
     /// - Throws: An error if the restart process fails.
     /// - Throws: An error if the restart process fails.
     /// - Returns: Void upon successful restart.
     /// - Returns: Void upon successful restart.
     @MainActor func performRestart() async throws {
     @MainActor func performRestart() async throws {
-        var backgroundTaskID: UIBackgroundTaskIdentifier = .invalid
-
         // Start background task
         // Start background task
-        backgroundTaskID = UIApplication.shared.beginBackgroundTask(withName: "Restart Live Activity") {
-            Task { @MainActor in
-                if backgroundTaskID != .invalid {
-                    UIApplication.shared.endBackgroundTask(backgroundTaskID)
-                    backgroundTaskID = .invalid
-                    debug(.default, "Background task expired and ended.")
-                }
-            }
-        }
+        var backgroundTaskID: UIBackgroundTaskIdentifier = .invalid
+        backgroundTaskID = startBackgroundTask(withName: "Restart Live Activity")
 
 
         guard backgroundTaskID != .invalid else {
         guard backgroundTaskID != .invalid else {
             debug(.default, "Failed to start background task.")
             debug(.default, "Failed to start background task.")
@@ -34,10 +25,6 @@ import UIKit
         await liveActivityManager.restartActivityFromLiveActivityIntent()
         await liveActivityManager.restartActivityFromLiveActivityIntent()
 
 
         // Ensure background task ends properly
         // Ensure background task ends properly
-        if backgroundTaskID != .invalid {
-            UIApplication.shared.endBackgroundTask(backgroundTaskID)
-            debug(.default, "Background task ended successfully.")
-            backgroundTaskID = .invalid
-        }
+        endBackgroundTaskSafely(&backgroundTaskID, taskName: "Restart Live Activity")
     }
     }
 }
 }