I have an application that uses Bonjour to communicate with other instances of the app on other devices.
If I start an NWBrowser
and the user has "Local Network" turned off for my app, the stateUpdateHandler
for the browser gets .waiting
with an error containing the string "PolicyDenied." This lets me show an alert to the user explaining what's happening, with a link to the app's Settings screen.
But if I use NWListener
(the counterpart of NWBrowser
) and have "Local Network" turned off, there's no indication of any problem. After I start the listener, stateUpdateHandler
is called with .ready
as the state - even though it's not really ready to listen at all.
The FAQ for Local Network Privacy suggests that any Bonjour operation will raise kDNSServiceErr_PolicyDenied
if Local Network is off. However, in my application, that only seems to be true for browsing, not listening.
Is there a way to detect a missing Local Network entitlement for NWListener
? I know there are solutions involving sending a message to localhost, etc, but ideally there would be something simpler.