◉RORK LABJP
●GPT-6.1 SOL — Added to Rork's model menu (09-29) with Low, Medium and High effort; included on Pro and Max●SONNET 5.5 — Claude Sonnet 5.5 is selectable: strong at UI design and faster than Sonnet 5 (09-28)●SDK 58 — Beta since 09/15 with no stable date yet; running projects in Expo Go has required login since 09/03●WIDGET — A write-up traces an iOS widget that renders black only in production builds●OBSERVE — EAS Observe now records native crashes too (SDK 57.0.21 or later, 10/07)●NEW — My App Open Ad Only Showed When the App…●GPT-6.1 SOL — Added to Rork's model menu (09-29) with Low, Medium and High effort; included on Pro and Max●SONNET 5.5 — Claude Sonnet 5.5 is selectable: strong at UI design and faster than Sonnet 5 (09-28)●SDK 58 — Beta since 09/15 with no stable date yet; running projects in Expo Go has required login since 09/03●WIDGET — A write-up traces an iOS widget that renders black only in production builds●OBSERVE — EAS Observe now records native crashes too (SDK 57.0.21 or later, 10/07)●NEW — My App Open Ad Only Showed When the App…
Articles/App Dev
◇ App Dev/2026-07-03Advanced

Keeping Downloads Alive After Your Rork Max App Is Killed: Background URLSession Design and Relaunch Handling

How to design downloads in a Rork Max native Swift app so transfers continue in the OS daemon even after the app is suspended or terminated. Covers relaunch wiring, resumeData recovery, and measured isDiscretionary behavior with working code.

Rork Max236URLSessionBackground TransferSwift48iOS116Downloads

✦ Premium Article

When I started shipping high-resolution image packs in one of my wallpaper apps, a pattern of reviews appeared: "downloads stop halfway, every time." Digging in, the cause was mundane. Users tapped download, went back to the home screen, and roughly thirty seconds later iOS suspended the app — taking the transfer down with it. As an indie developer staring at server logs, all I could see was "client closed connection." It took me days to trace it back to the app's own lifecycle.

The fix was architectural, not incremental. A standard URLSession lives and dies with your process. If you want a transfer to survive suspension — or outright termination — you have to hand the transfer itself to the operating system through a background session.

Because Rork Max generates native Swift, this machinery is fully available to you. But if you write against it with the same habits you use for ordinary sessions, you will hit runtime crashes and silently vanishing files. What follows is the setup I actually run for delivering add-on content packs, walking through each design decision in order.

The Transfer Belongs to nsurlsessiond, Not Your App

The essence of a background session is that the transfer's execution moves out of your process. The real worker is a system daemon called nsurlsessiond. Your app can be suspended, or jettisoned under memory pressure, and the bytes keep flowing.

Here is how the two session types differ in practice.

AspectStandard sessionBackground session
Where the transfer runsInside your app's processnsurlsessiond (out of process)
After the app is suspendedTransfer is cut offTransfer continues
After the app is terminatedTransfer is goneTransfer continues; the app is relaunched on completion
Completion-handler APIsAvailableUnavailable (runtime exception)
DelegateOptionalRequired
dataTaskAvailableNot supported in practice (download/upload tasks only)

The last two rows are where most people trip first. Closure-based calls like session.downloadTask(with: url) { location, response, error in ... } throw the moment you invoke them on a background configuration. Since the task may finish while your app does not exist, there is nothing to hold that closure — every result must arrive through a delegate.

Creating the Session and Its Three Constraints

Start with a singleton manager. Creating multiple sessions with the same identifier leads to undefined behavior, so keep construction in exactly one place.

// BackgroundDownloadManager.swift
import Foundation
 
final class BackgroundDownloadManager: NSObject {
    static let shared = BackgroundDownloadManager()
    static let sessionIdentifier = "com.example.app.asset-downloads"
 
    /// Handed to us by the AppDelegate when the app is relaunched
    var backgroundCompletionHandler: (() -> Void)?
 
    private lazy var session: URLSession = {
        let config = URLSessionConfiguration.background(
            withIdentifier: Self.sessionIdentifier)
        config.sessionSendsLaunchEvents = true  // wake the app after termination
        config.isDiscretionary = false          // run immediately (more below)
        config.allowsCellularAccess = true
        return URLSession(configuration: config,
                          delegate: self,
                          delegateQueue: nil)
    }()
 
    func download(_ url: URL) {
        let task = session.downloadTask(with: url)
        // Telling the OS the expected size stabilizes its scheduling
        task.countOfBytesClientExpectsToReceive = 20_000_000
        task.resume()
    }
}

What this code buys you is the decoupling of a started download from your app's lifecycle. Three constraints to internalize:

First, the delegate can only be supplied at initialization. There is no API to swap it later, which is why passing the singleton's self is the natural shape.

Second, without sessionSendsLaunchEvents = true, the system will not relaunch your app when a transfer finishes after termination. It defaults to true, but I write it out to make the intent explicit.

Third, identifiers must be unique within your app. If you want separate sessions per feature, give each its own identifier and its own independent delegate.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦Walk away with a working Swift download foundation where transfers keep running in the OS daemon even after your app is suspended or killed
✦Understand the correct wiring for handleEventsForBackgroundURLSession in a SwiftUI app, including when to hold and when to call the completion handler
✦Avoid the production traps in advance: resumeData recovery, synchronous temp-file moves, and the measured real-world behavior of isDiscretionary
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Rork Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

⬡ Dev Tools2026-04-05
Rork Max × WidgetKit & Live Activities in Practice — From Home Screen to Dynamic Island
A complete guide to implementing iOS Widgets, Lock Screen widgets, and Dynamic Island Live Activities with Rork Max. Covers WidgetKit fundamentals, Timeline update strategies, App Intents integration, and monetization.
◇ App Dev2026-10-15
When adjustsFontSizeToFit Shrinks Just One Row, Suspect the Box Height, Not the String
Only the 10th row of a list drops to 4pt on iOS, though the data and strings are fine. I read the Yoga rounding and font-fit sources, then counted how often the box comes up short in Node.
◇ App Dev2026-04-26
Native iOS Apps with Rork: SwiftUI to TestFlight
New iPhone projects in Rork are generated in Swift and SwiftUI, and Rork Pro carries them all the way to the App Store. How to tell an old Expo project from a new one, costs in credits, the skeleton prompt, device testing, when to drop into Xcode, and TestFlight submission.