Background and Locked-Screen Recording
Read this first. No physical iPhone was available during development. Everything on this page is implemented with the APIs Apple documents for the purpose, and none of it has been observed on a device. Simulator testing cannot stand in for it.
Mermaid source
stateDiagram-v2 [*] --> Idle Idle --> Recording: start Recording --> Paused: pause Paused --> Recording: resume Recording --> Interrupted: system interruption Interrupted --> Recording: shouldResume, or user tap Recording --> Finishing: stop Paused --> Finishing: stop Interrupted --> Finishing: stop Finishing --> Idle: verified file in library Recording --> ProcessEnded: kill, crash, power loss ProcessEnded --> RecoveryOffer: next launch RecoveryOffer --> Idle: recover or discard
What makes it work
| Requirement | Implementation |
|---|---|
| Permission to run in the background | UIBackgroundModes contains audio (project.yml) |
| An active record-capable session | .playAndRecord, activated before the engine starts |
| Files writable while locked | protection class complete until first user authentication on the library and capture folders and on each master |
| A visible indication | the system microphone indicator, plus a Live Activity |
| Time to finish after stop | a UIApplication background task around draining and encoding |
The protection class matters. With the stricter complete class, iOS makes files unreadable and unwritable shortly after the device locks, and every write from a pocket would fail. The chosen class encrypts files at rest and unlocks them after the first unlock following a restart.
Lock Screen and Dynamic Island
ORIXAudioWidgets/RecordingLiveActivity.swift presents the recording title, a status line, an elapsed-time display and two buttons. While recording, the time is a system-rendered timer counting up from updatedAt − elapsed, so it advances without the app pushing updates; while paused it is a fixed value. The buttons are LiveActivityIntents — pause/resume and add marker — which iOS runs in the app's process. Activities left over from a terminated process are ended at launch.
Apple offers no API for arbitrary microphone controls on the Lock Screen; a Live Activity with intents is the supported route, and that is all the app claims.
Interruptions
On AVAudioSession.interruptionNotification:
- began — capture pauses, a marker labelled "⚠︎ Interrupted" is written at the current position, the Live Activity shows the state. Everything captured so far is already on disk.
- ended — if the system includes
.shouldResume, the session is reactivated and recording resumes; otherwise the app waits for the user and says so.
On mediaServicesWereResetNotification the recording is stopped and saved up to that point.
What the app does not do
- It does not record without a visible indicator.
- It does not use unsupported tricks to stay alive (silent audio playback, location updates and the like).
- It does not claim to survive force-quit, device shutdown or every interruption. When the process ends, the master on disk is offered for recovery at the next launch.
Device test plan
To be run on a physical iPhone before any release; none of these has been done.
- Record 60 minutes with the screen locked and the phone in a pocket; compare the file duration with a stopwatch.
- Receive a phone call during a recording; decline it; accept it; check the marker and the resumed audio.
- Trigger an alarm and a Siri request during a recording.
- Connect and disconnect wired headphones, AirPods and a USB microphone mid-recording.
- Use the Live Activity buttons from the Lock Screen and the Dynamic Island.
- Force-quit during a recording; relaunch; recover.
- Record until storage is nearly full.
- Measure battery drain per hour with the waveform visible and with the screen locked.