React Native Voice Session Terminating in Background

Hi all, I’m developing an app with React Native (Expo) using the LiveKit React Native SDK and I’m running into an issue with background connections while the phone is off. Only tested on iOS at the moment, but when the phone is turned off the connection lasts for 45 seconds - 1 minute or so before abruptly cutting off.

Does anyone know how I can keep this alive (indefinitely)? Being able to chat in the background/with the phone off seems important.

Thanks

You cannot keep a LiveKit/WebRTC data connection alive indefinitely on iOS with the phone locked unless the app has an allowed background reason.

For iOS, a plain chat/data-channel connection is not enough. Once the app is backgrounded/locked, iOS suspends it after a short grace period, which matches with the 45–60 second cutoff you’ve reported. See network activity alone is not a valid reason to keep apps running in the background on iOS. Apple expects apps to use supported modes like audio, location, VoIP push, etc., not persistent background sockets.

With LiveKit, the supported path is background audio. LiveKit allows iOS apps to continue a voice call in the background if Background Modes are enabled with Audio, AirPlay, and Picture in Picture.

Try adding this in your XML:

<key>UIBackgroundModes</key>
<array>
  <string>audio</string>
</array>

Say a user is in an active audio room/call, then enable iOS background audio mode and keep an actual audio session active.

If this is only chat/data messages, don’t try to keep LiveKit connected indefinitely in the background it won’t work. Use push notifications/APNs for new messages, then reconnect/resync when the app returns to foreground.

As for Expo, this likely means adding the iOS background mode in app.json / app.config.js, but if you need a deeper native audio-session handler, you may need to go with a custom dev client or a prebuild rather than pure Expo Go.

Hope it helps.

Of course. I’m using a development build and I’ve got “audio” in “UIBackgroundModes” in the app config. I thought that would be enough to have it run in the background while the phone is off, but its still cutting off after 45 seconds - 1 min as I mentioned.

Yeah unlike Android iOS devices kill idol apps from active ram after a short period of time they call a “grace period”, IDK why they call it grace as its not graceful, maybe to their battery it might be.

UIBackgroundModes: audio only gives the app permission to continue background audio; it does not by itself keep a WebRTC connection alive. iOS will still suspend the app if there is no active audio session/track especially if it contains a 3000ms delay (the suspend timer active refresh rate) at any point while it is in the background/screen locked. If the room is effectively silent for any 3000ms’s or chat-only, the 45–60 second cutoff will be active. For LiveKit RN, make sure AudioSession.startAudioSession() is called and that the room has an active mic or remote audio track with white-noise at a higher frequency than the human ear can hear to fool the kill app timer. As it only see’s the data packets not the sound, empty air equals empty packets.

Also adding voip alongside audio in UIBackgroundModes wouldn’t hurt. But if the goal is indefinite background calls with the screen locked, that is not something iOS reliably permits except for network/wifi calling. I assume voip calls are treated like wifi calls.

Hope this helps.