         return true
     }
 
-    private func setupFilestackClient() {
+    func applicationDidEnterBackground(_ application: UIApplication) {
+        if let client = client, client.sdkClient.isUploading {
+            beginBackgroundTaskForFilestack()
+        }
+    }
+
+    func applicationWillEnterForeground(_ application: UIApplication) {
+        endBackgroundTaskForFilestack()
+    }
+
+}
+
+private extension AppDelegate {
+    func setupFilestackClient() {
         // Set `UploadService.shared.useBackgroundSession` to true to allow uploads in the background.
         FilestackSDK.UploadService.shared.useBackgroundSession = true
 


        return customSource
    }
}

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    var backgroundTaskID: UIBackgroundTaskIdentifier? = nil

    func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        setupFilestackClient()
