RORK LABJP
BUILD — Rork Max runs real Macs in the cloud loaded with Xcode and the iOS SDK, writing SwiftUI, compiling, reading the errors and building again. That loop, not the code generation, is what lifts the outputNATIVE — What comes out is pure Swift and SwiftUI, not React Native. Reaching AR, Metal graphics and widgets that React Native cannot touch is the real gap between this and other buildersPLATFORMS — Coverage spans iPhone, iPad, Apple Watch, Apple TV and Vision Pro, plus iMessage. Worth a look if you want to start from a watch app or an extension rather than a phone screenCOMPANION — The Rork Companion app lets you check a generated build on a real iPhone without a paid Apple Developer account, lowering the bar for trying a first project end to endPRICING — Free to start, paid plans from $25 a month, and Rork Max on the $200 Max plan. Worth working out up front how many projects it takes to earn that backDEADLINE — From August 31, 2026, Google Play requires target API level 36 or higher for new apps and updates alike. Ten days out, and the targetSdkVersion of what you generate is yours to verifyBUILD — Rork Max runs real Macs in the cloud loaded with Xcode and the iOS SDK, writing SwiftUI, compiling, reading the errors and building again. That loop, not the code generation, is what lifts the outputNATIVE — What comes out is pure Swift and SwiftUI, not React Native. Reaching AR, Metal graphics and widgets that React Native cannot touch is the real gap between this and other buildersPLATFORMS — Coverage spans iPhone, iPad, Apple Watch, Apple TV and Vision Pro, plus iMessage. Worth a look if you want to start from a watch app or an extension rather than a phone screenCOMPANION — The Rork Companion app lets you check a generated build on a real iPhone without a paid Apple Developer account, lowering the bar for trying a first project end to endPRICING — Free to start, paid plans from $25 a month, and Rork Max on the $200 Max plan. Worth working out up front how many projects it takes to earn that backDEADLINE — From August 31, 2026, Google Play requires target API level 36 or higher for new apps and updates alike. Ten days out, and the targetSdkVersion of what you generate is yours to verify
Articles/Dev Tools
Dev Tools/2026-06-24Advanced

Audio Apps That Survive Calls, Unplugged Headphones, and Other Apps Taking Over

How to handle AVAudioSession interruption and route-change notifications correctly so playback survives calls and headphone unplugs, with working Swift code.

Rork Max233AVFoundationAudioSwiftUI64Background Playback

Premium Article

When I shipped a small app, built as an indie developer, that plays meditation and study audio, the very first bug report read: "after a phone call, the sound doesn't come back." It is natural for audio to stop when a call comes in mid-playback, but even after the call ended, the app stayed paused, with the on-screen play button frozen in its "playing" look.

The cause was that I was not handling AVAudioSession interruptions at all. Playback was left entirely to AVAudioPlayer, and my code was not listening to the OS telling it "I've interrupted you now" and "you may resume." I learned the hard way that the quality of an audio app is decided less by whether the features run and more by how carefully it answers this kind of interruption.

This article walks through handling interruptions from calls and Siri, and route changes from plugging and unplugging headphones, in a form you can drop straight into the native Swift that Rork Max generates.

First, decide the audio session category

Before anything else, declare to the OS what kind of audio app this is. Skip it and your sound may vanish with the silent switch, or you may needlessly stop another app's music.

import AVFoundation
 
func configureAudioSession() {
    let session = AVAudioSession.sharedInstance()
    do {
        // A playback-first app: plays regardless of the silent switch
        try session.setCategory(.playback, mode: .default)
        try session.setActive(true)
    } catch {
        print("Audio session setup failed: \(error)")
    }
}

.playback declares "this app's sound is the content itself," letting it play while locked or in the background. Conversely, if you only want to layer a short effect over another app's music, you would choose .ambient. Choosing the right declaration up front is the foundation for every later behavior.

Subscribe to interruption notifications

Interruptions arrive via AVAudioSession.interruptionNotification. There are two phases — .began and .ended — and the end carries a hint about whether you may resume on your own.

final class PlaybackController {
    private var wasPlayingBeforeInterruption = false
 
    func observeInterruptions() {
        NotificationCenter.default.addObserver(
            self, selector: #selector(handleInterruption),
            name: AVAudioSession.interruptionNotification, object: nil)
    }
 
    @objc private func handleInterruption(_ note: Notification) {
        guard let info = note.userInfo,
              let raw = info[AVAudioSessionInterruptionTypeKey] as? UInt,
              let type = AVAudioSession.InterruptionType(rawValue: raw) else { return }
 
        switch type {
        case .began:
            // A call or Siri broke in. Remember the state.
            wasPlayingBeforeInterruption = player.isPlaying
            player.pause()
 
        case .ended:
            guard let optsRaw = info[AVAudioSessionInterruptionOptionKey] as? UInt else { return }
            let options = AVAudioSession.InterruptionOptions(rawValue: optsRaw)
            // Resume only if shouldResume is set AND we were playing before
            if options.contains(.shouldResume), wasPlayingBeforeInterruption {
                try? AVAudioSession.sharedInstance().setActive(true)
                player.play()
            }
 
        @unknown default:
            break
        }
    }
}

The crux here is how you treat shouldResume. The OS distinguishes "interruptions you may resume from" and "interruptions you should not." For example, when another music app comes to the front by the user's action, you should not grab playback back on your own. Resuming when shouldResume is not set goes against the user's intent. Check whether you were playing before the interruption as well, and only restore quietly when both hold — that is the well-behaved implementation.

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
You can subscribe to AVAudioSession interruption (calls, Siri) and route-change (headphone unplug) notifications correctly so playback never breaks
You'll separate the cases where you may resume on your own from the ones where you should wait for the user, using the shouldResume flag
You'll wire up Now Playing and remote commands to ship a production-grade audio app controllable from the lock screen and Control Center
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-07-18
The Generated Screen That Quietly Jams at AX5 and in German — Putting Layout Resilience Checks on Rork Max SwiftUI
A record of running every Rork Max generated SwiftUI screen through pseudolocalization and the largest text size to find exactly where it jams. Covers when to reach for ViewThatFits, ScaledMetric and layoutPriority, plus the snapshot checks that catch regressions every time you regenerate.
Dev Tools2026-07-12
A symbolEffect Field Memo: Making Icons Move Nicely in Your Rork Max App
Animate SF Symbols in a Swift app generated by Rork Max using bounce, pulse, variableColor, and contentTransition, with working code, OS-version gating, and the mistakes I made from over-animating.
Dev Tools2026-07-09
Getting Rork Max's Swift Through Swift 6's Strict Concurrency Checking
A field record of taking a Rork Max-generated SwiftUI app through Swift 6 complete concurrency checking: 217 warnings cleared target by target, where @MainActor actually belongs, and measured before/after numbers.
📚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 →