RORK LABJP
FUNDING — Rork's $15M seed was led by Left Lane Capital with Peak XV, True Ventures, Goodwater, and a16z SpeedrunGROWTH — Rork keeps growing with 743K monthly visits and an 85% growth rateMAX — Rork Max generates native Swift apps for iPhone, iPad, Watch, TV, Vision Pro, and iMessageMAX — It reaches HealthKit, Core ML, and Dynamic Island — territory React Native struggles withMARKET — Apple pushes agentic coding in Xcode 27, accelerating AI-driven native developmentMARKET — Gartner projects 75% of new apps will be low-code or no-code by the end of 2026FUNDING — Rork's $15M seed was led by Left Lane Capital with Peak XV, True Ventures, Goodwater, and a16z SpeedrunGROWTH — Rork keeps growing with 743K monthly visits and an 85% growth rateMAX — Rork Max generates native Swift apps for iPhone, iPad, Watch, TV, Vision Pro, and iMessageMAX — It reaches HealthKit, Core ML, and Dynamic Island — territory React Native struggles withMARKET — Apple pushes agentic coding in Xcode 27, accelerating AI-driven native developmentMARKET — Gartner projects 75% of new apps will be low-code or no-code by the end of 2026
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 Max207URLSessionBackground TransferSwift35iOS97Downloads

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

App Dev2026-06-16
Staging Wallpaper Packs Before the First Launch: Where Rork Max and Background Assets Fit
Content-heavy apps tend to greet new users with an empty grid. Background Assets downloads content out-of-band, ahead of the first launch. Here is how I implement it in Rork Max's native Swift, a domain Rork (Expo) cannot reach easily, plus how I decide when it is worth it.
App Dev2026-06-16
Building a WeatherKit App with Rork Max — The Auth and Attribution Pitfalls
When you add WeatherKit to a native Swift app generated by Rork Max, the first walls are authentication and attribution. Here is the workflow I confirmed: token handling, rate limits, and the mandatory data-source display.
App Dev2026-07-02
Adding Game Center to a Rork Max Game: Authentication, Leaderboards, Achievements, and Living with Score Tampering
How to add Game Center to a Rork Max iOS game — working Swift code for authentication, leaderboards, and achievements, plus a realistic approach to score tampering.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →