Bonjour trouble using iOS 15, detecting "Local Network" setting
Asked Answered
I

0

1

Starting with iOS 15 (and maybe iOS 14), I had been having trouble getting Bonjour to work (it's working now). I am using MCSession, MCAdvertiserAssistant, and MCNearbyServiceBrowser. None of my delegate methods were being triggered. It was radio silence. (Everything worked fine with prior iOS versions.)

Eventually, I figured out that I had to turn on my app's Local Network switch in the device settings. There's no documentation about this and Apple provides no easy way for an app to detect if the switch is turned off.

I found a forum posting about Bonjour, Local Network Privacy FAQ, written by Quinn “The Eskimo!” (Apple Developer Technical Support). https://developer.apple.com/forums/thread/663858. FAQ #9, titled How do I tell whether I’ve been granted local network access?, offers an indirect way to learn if the Local Network switch is off. That FAQ says:

If you’re using Bonjour, you will get the kDNSServiceErr_PolicyDenied (-65570) error if your Bonjour operation failed because you don’t have local network access.

All of the methods I can find that return an error (e.g., MCSession's sendData:toPeers:withMode:error:) depend on my passing a local peer ID, but I don't have any peer IDs (other than my own) because none of my delegate methods return any information (which is how I'd learn about nearby peers). If I don't provide a peerID, then the errors I get from that method are about not providing a valid nearby peer ID, not the kDNSServiceErr_PolicyDenied error that I'm looking for.

The FAQ thread is locked, so I cannot ask this question there.

What method do I use to get the kDNSServiceErr_PolicyDenied error?

I'm using Objective-C and Xcode 13.2.1.


FYI, my Info.Plist includes these keys: NSBonjourServices (array with _MyServiceType._tcp and _MyServiceType._udp), NSBluetoothAlwaysUsageDescription, NSBluetoothPeripheralUsageDescription, and NSLocalNetworkUsageDescription.

Ideate answered 14/2, 2022 at 9:2 Comment(1)
Beautiful! I just needed this. There were a lot of Bonjour changes in iOS 15 …Infusionism

© 2022 - 2024 — McMap. All rights reserved.