Skip to content

Commit c1edfad

Browse files
committed
Remove BackgroundTaskCreator
1 parent b2fd819 commit c1edfad

File tree

1 file changed

+2
-28
lines changed

1 file changed

+2
-28
lines changed

Sources/SwiftAudioKit/Utils/BackgroundHandler.swift

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,13 @@
99
import Foundation
1010
#else
1111
import UIKit
12-
13-
/// A protocol that defines background task handling capabilities.
14-
protocol BackgroundTaskCreator: AnyObject {
15-
/// Marks the beginning of a new long-running background task.
16-
///
17-
/// - Parameter handler: A handler to be called shortly before the app’s remaining background time reaches 0.
18-
/// You should use this handler to clean up and mark the end of the background task. Failure to end the task
19-
/// explicitly will result in the termination of the app. The handler is called synchronously on the main
20-
/// thread, blocking the app’s suspension momentarily while the app is notified.
21-
/// - Returns: A unique identifier for the new background task. You must pass this value to the
22-
/// `endBackgroundTask:` method to mark the end of this task. This method returns `UIBackgroundTaskInvalid`
23-
/// if running in the background is not possible.
24-
func beginBackgroundTask(expirationHandler handler: (() -> Void)?) -> UIBackgroundTaskIdentifier
25-
26-
/// Marks the end of a specific long-running background task.
27-
///
28-
/// You must call this method to end a task that was started using the `beginBackgroundTask(expirationHandler:)`
29-
/// method. If you do not, the system may kill your app.
30-
///
31-
/// This method can be safely called on a non-main thread.
32-
///
33-
/// - Parameter identifier: An identifier returned by the `beginBackgroundTask(expirationHandler:)` method.
34-
func endBackgroundTask(_ identifier: UIBackgroundTaskIdentifier)
35-
}
36-
37-
extension UIApplication: BackgroundTaskCreator {}
3812
#endif
3913

4014
/// A class that handles background tasks to prevent iOS from suspending the app while tasks are ongoing.
4115
class BackgroundHandler: NSObject {
4216
#if !os(OSX)
4317
/// The background task creator, typically `UIApplication.shared`.
44-
var backgroundTaskCreator: BackgroundTaskCreator = UIApplication.shared
18+
var backgroundTaskCreator: UIApplication = UIApplication.shared
4519

4620
/// The background task identifier if a background task has started. `nil` if not.
4721
@SynchronizedLock private var taskIdentifier: UIBackgroundTaskIdentifier?
@@ -97,7 +71,7 @@ class BackgroundHandler: NSObject {
9771
guard counter == 0 else {
9872
return false
9973
}
100-
74+
UIApplication.shared.beginBackgroundTask()
10175
if taskIdentifier != UIBackgroundTaskIdentifier.invalid {
10276
backgroundTaskCreator.endBackgroundTask(taskIdentifier)
10377
}

0 commit comments

Comments
 (0)