product

Three Pitfalls Building a DLNA Renderer in SwiftUI

The phone can't find the device, then the device errors out, then video freezes on the first frame — each of these cost us days while building StreamPort's DLNA renderer.

StreamPort has a feature: put the phone and the Mac on the same Wi-Fi, tap “cast” in a live-streaming app, and the picture appears on the Mac.

Sounds small. Building the DLNA receiver side of it, we got stuck three times — and each time we assumed the code was wrong, before finding the problem was somewhere else.

These are the three.

Pitfall one: the phone can’t see you at all

First version done, we opened a live-streaming app on the phone and tapped cast. Empty device list.

Our first assumption was that SSDP was sending wrong. It wasn’t sending wrong — the problem was receiving.

macOS App Sandbox blocks inbound network connections by default. DLNA discovery relies on multicast — devices announce to 239.255.255.250:1900, and anything listening receives it. To receive that packet, the app must declare the com.apple.security.network.server entitlement.

Without it, nothing errors. The multicast packets are simply, silently, never received. No log line. That’s an order of magnitude harder to debug than a crash.

With the entitlement added, a second cause showed up: some routers drop multicast. Enterprise APs with client isolation, guest networks with the same — devices on the same Wi-Fi can’t see each other even though the app is perfectly correct. That’s a network-layer problem the app can’t fix.

The fallback we added: a manual entry where the user types the Mac’s LAN IP. It’s a concession — multicast is not always reliable.

Pitfall two: the device appears, then errors out

With the entitlement, the device finally showed up in the phone’s cast list. Tapped it. Spinners. Error.

This layer lives in the UPnP spec: discovery is only step one — the phone then comes back to ask who you are.

The phone issues an HTTP request for an XML device description. That document has to state:

  • deviceType must be exactly urn:schemas-upnp-org:device:MediaRenderer:1 — one wrong character and the phone won’t accept it
  • The AVTransport service must be declared, with three URLs: controlURL (commands), eventSubURL (events), SCPDURL (service description)
  • friendlyName is what appears on the phone
  • Every URL’s port must match what the HTTP server actually listens on

Our first XML was missing the file behind SCPDURL. The phone fetched it, didn’t find what it expected, and silently gave up.

The trap here: different phone brands tolerate missing fields differently. Some limp along; others stop dead on one omission. Testing on a single handset tells you almost nothing — try three or four brands.

Pitfall three: video freezes on the first frame

XML correct, phone connected. The picture arrives — and sits on frame one.

One concept has to be clear first: DLNA casting is not push streaming. The phone hands the Mac a URL, and the Mac pulls it.

The phone does two things: SetAVTransportURI tells the receiver “fetch this address”, and then it expects playback to start.

The problem: some phones follow that with an explicit Play command, and some don’t — they assume setting the URI implies playing. Implement strictly as “only play on Play”, and you sit on frame one with the second kind of phone.

The fix: start playback proactively after SetAVTransportURI, and treat an incoming Play as an idempotent repeat. The spec doesn’t say this. It’s what compatibility actually requires.

Same layer, second issue: the scrub bar doesn’t work.

Seeking requires the HTTP server to support Range requests — the player sends Range: bytes=1000000-, the server must answer 206 with the matching slice. Without it, the player can only stream from the start, and the scrub bar is decoration.

That isn’t a DLNA problem; it’s an HTTP server implementation detail. But a user who can’t drag the progress bar concludes “this app is broken”, not “the server lacks Range support”.

What the three have in common

None were “the code is wrong”. All were things the spec doesn’t mention but reality demands:

  • Sandbox entitlement failures are silent, not loud
  • Phone brands tolerate malformed XML differently
  • “Set the URI” and “start playing” mean different things in different implementations

Only after all three did the feature actually work. StreamPort 1.0.4 has fallbacks for each: manual IP entry, multi-brand-compatible XML, proactive playback plus Range support.

Why write this up

People who build tools and people who use them define “working” differently.

The user sees “tap once, picture appears”. The pits in between are invisible to them — but someone has to fall into them first.

It’s also why we built StreamPort at all. Casting a phone livestream to an event screen used to mean installing an app on the phone or wrestling with configuration. Writing our own was the only way to find out why each step is hard.


StreamPort is at 1.0.4 now — macOS 13 and up, Apple Silicon, direct download from this site, 2.9 MB, no account required.

If you’re building something similar, or hit a pitfall we didn’t mention, get in touch.

← All articles

Have a similar event coming up?

Send the date, venue and scale. We will come back with a plan.

Let's talk↗