Every now and then I talk to someone who’s trying to use Bonjour and just can’t get over the first hurdle. That happened today, and so I decided to share my write-up for the benefit of others.
Questions or comments? Put them in a new thread here on DevForums, tagging it with Bonjour so that I see it.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
Getting Started with Bonjour
Bonjour is an Apple term for a variety of Internet standards [1]. Bonjour allows your app to browse for and connect to services on the network without infrastructure support. For example, Bonjour lets you find and connect to a printer even if the network has no DHCP server to hand out IP addresses.
If you’re new to Bonjour, a good place to start is the Bonjour Overview. It’s in the documentation archive, so it hasn’t been updated in a while, but the fundamentals haven’t changed.
There are, however, two things that have changed:
Network framework has new Bonjour APIs, and the old ones are now deprecated.
iOS 14 introduced local network privacy.
This post shows how to get started with Bonjour, taking into account these new developments.
[1] Specifically:
RFC 3927 Dynamic Configuration of IPv4 Link-Local Addresses
RFC 6762 Multicast DNS
RFC 6763 DNS-Based Service Discovery
Start Browsing
Let’s start by implementing a service browser. To simplify things, this browses for SSH services. That way you can get started with the browser without first having to implement a server to register your service. If you don’t already have an SSH service registered on your network, start one by enabling System Settings > General > Sharing > Remote Login on your Mac.
The SSH service type is, unsurprisingly, _ssh._tcp. First, on your Mac, run the dns-sd tool to confirm that you have an SSH service visible on your network:
% dns-sd -B "_ssh._tcp" "local."
% dns-sd -B "_ssh._tcp" "local."
…
Timestamp A-R Flags if Domain Service Type Instance Name
…
11:54:43.315 Add 2 6 local. _ssh._tcp. Fluffy
…
11:54:43.725 Add 2 6 local. _ssh._tcp. SAM the Robot 12
^C
This shows that I have two services, one called Fluffy and the other called SAM the Robot 12. Let’s write some iOS code to browse for those. To start, create an app from the iOS > App template and connect a button to the startStop() method of a class like this:
import Foundation
import Network
class AppModel {
var browserQ: NWBrowser? = nil
func start() -> NWBrowser {
print("browser will start")
let descriptor = NWBrowser.Descriptor.bonjour(type: "_ssh._tcp", domain: "local.")
let browser = NWBrowser(for: descriptor, using: .tcp)
browser.stateUpdateHandler = { newState in
print("browser did change state, new: \(newState)")
}
browser.browseResultsChangedHandler = { updated, changes in
print("browser results did change:")
for change in changes {
switch change {
case .added(let result):
print("+ \(result.endpoint)")
case .removed(let result):
print("- \(result.endpoint)")
case .changed(old: let old, new: let new, flags: _):
print("± \(old.endpoint) \(new.endpoint)")
case .identical:
fallthrough
@unknown default:
print("?")
}
}
}
browser.start(queue: .main)
return browser
}
func stop(browser: NWBrowser) {
print("browser will stop")
browser.stateUpdateHandler = nil
browser.cancel()
}
func startStop() {
if let browser = self.browserQ {
self.browserQ = nil
self.stop(browser: browser)
} else {
self.browserQ = self.start()
}
}
}
Note I’m using SwiftUI, but if you chose to use UIKit you could add this code directly to your view controller. Of course, whether you want to add networking code to your view controller is another question. The answer is, natch, “No”, except when creating a tiny test project like this one (-:
Now build and run in the simulator and click your buton. It’ll print something like this:
browser will start
browser did change state, new: ready
browser results did change:
+ SAM the Robot 12._ssh._tcp.local.
+ Fluffy._ssh._tcp.local.
As you can see, it’s found our two SSH services. Yay!
Run on the Device
Now stop the app and run it on a real device. This time the Test button results in:
browser will start
…
browser did change state, new: failed(-65555: NoAuth)
This is local network privacy kicking in. There are two things you need to do:
Add a NSBonjourServices property to your Info.plist to declare what service types you’re using.
Add a NSLocalNetworkUsageDescription property to your Info.plist to explain what you’re doing with the local network.
Do that and run your app again. On tapping the Test button you’ll see an alert asking you to grant your app access to the local network. Tap Allow and the browser will start generating results as before.
Respond to Updates
When working with Bonjour it’s important to keep your browser running to update your app’s state. To test this, start a Remote Login on a different machine and look for a new result being printed:
browser results did change:
+ Slimey._ssh._tcplocal.
And then turn it off:
browser results did change:
- Slimey._ssh._tcplocal.
If you don’t have another Mac to test this with, start a dummy service using dns-sd:
% dns-sd -R "Guy Smiley" "_ssh._tcp" "local." 12345
Registering Service Test._ssh._tcp.local. port 12345
…
Press control-C to stop the dns-sd tool, which unregisters the service.
Connect
When the user choose a service, it’s time to connect. There are two ways to do this, depending on the networking API you use to run your connection.
NWConnection can connect directly to a Bonjour service endpoint. For example, you might have code that connects to a DNS name and port:
func makeConnection(host: String, port: UInt16) -> NWConnection {
let host = NWEndpoint.Host(host)
let port = NWEndpoint.Port(rawValue: port)!
let endpoint = NWEndpoint.hostPort(host: host, port: port)
return NWConnection(to: endpoint, using: .tcp)
}
Replace that with code that takes the endpoint you get back from the browser:
func makeConnection(endpoint: NWEndpoint) -> NWConnection {
return NWConnection(to: endpoint, using: .tcp)
}
If you’re using a legacy API, like BSD Sockets, you’ll need to resolve the Bonjour service endpoint to a DNS name and then pass that DNS name into your connection code. Network framework does not support resolving Bonjour service endpoints out of the box, so you’ll have to do that yourself. For an example of how you might do this, see this post.
IMPORTANT For this to work reliably, your BSD Sockets code must support Happy Eyeballs. See TN3151 Choosing the right networking API for specific advice on that front.
Register a Service
Now let’s look at the server side. To listen for connections with Network framework, you might write code like this:
import Foundation
import Network
class AppModel {
var listenerQ: NWListener? = nil
func start() -> NWListener? {
print("listener will start")
guard let listener = try? NWListener(using: .tcp) else { return nil }
listener.stateUpdateHandler = { newState in
print("listener did change state, new: \(newState)")
}
listener.newConnectionHandler = { connection in
connection.cancel()
}
listener.start(queue: .main)
return listener
}
func stop(listener: NWListener) {
print("listener will stop")
listener.stateUpdateHandler = nil
listener.cancel()
}
func startStop() {
if let listener = self.listenerQ {
self.listenerQ = nil
self.stop(listener: listener)
} else {
self.listenerQ = self.start()
}
}
}
To register your service with Bonjour, add these lines before the call to start(queue:):
listener.service = .init(type: "_ssh._tcp")
listener.serviceRegistrationUpdateHandler = { change in
print(change)
}
The listener calls your service registration update handler to tell you the name of the service. Typically you display this value somewhere in your UI. For more about this, see Showing Connection Information in an iOS Server.
To confirm that your service is running, open Terminal and choose Shell > New Remote Command. Your service should show up in the Secure Shell (ssh) list.
Alternatively, browse for SSH services using the dns-sd tool, as illustrated in the Start Browsing section above.
Bonjour
RSS for tagBonjour, also known as zero-configuration networking, enables automatic discovery of devices and services on a local network using industry standard.
Posts under Bonjour tag
47 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Good morning,
I have been playing with he new Networking framework released in beta, and i think its amazing how powerful and simple it is.
However i have been tackling some issues with it, it seems that the NetworkListener does not allow us to configure a specific endpoint for any of the protocols, UDP, TCP (QUIC, TLS)
Is this intended or just not missing features as of the Beta ?
I figured out how to use bonjour to get a port (as i am brand new to using Networking on macOS and Swift)
I get that the use of this is mainly as a client to connect to servers, but it would make more sense to have a high level abstraction of what already exist, wouldn't it be more intuitive to configure a NetworkEndpoint that contains either a Bonjour Service or an endpoint with configured port that we can then configure on the Listener, instead of doing .service(...) ?
Hello everyone,
Last year I built an application for tvOS and iPadOS that enables device-to-device communication. I based it on Apple’s sample code, available here:
https://developer.apple.com/documentation/Network/building-a-custom-peer-to-peer-protocol
At that time, everything worked flawlessly. However, this year I had to revisit the project to add new features, and now it no longer works as expected. The first time the app runs it connects fine, but if we relaunch it (on either the iPad, the Apple TV, or both), the connection fails.
Most importantly, this is not an issue with my own code — I tested it directly with the original Apple sample code, and the exact same problem occurs there too.
Here’s what I see in the logs:
nw_endpoint_flow_setup_channel [C1 TicTacToe,65E91B02-890E-4D30-88B8-CE2AB9677BF9 in_progress channel-flow (satisfied (Path is satisfied), viable, interface: utun0, scoped, ipv6)] nexus assignment error Connection refused
nw_endpoint_flow_failed_with_error [C1 TicTacToe,65E91B02-890E-4D30-88B8-CE2AB9677BF9 in_progress channel-flow (satisfied (Path is satisfied), viable, interface: utun0, scoped, ipv6)] already failing, returning
code-block
This happens right after I select the iPad from the device list and try to connect.
What’s strange is that the interface being used is utun0. I don’t have a VPN or iCloud Private Relay enabled. I also tried running the app through the iPad’s personal hotspot, but I get the same error. The only workaround I’ve found so far is to restart the Apple TV.
Has anyone else run into this problem? Is there any known solution or workaround?
Tested on tvOS 18.6 and iPadOS 18.3.2 / 18.6.
I'm writing an application that implements a Bonjour service and browser for the purpose of connecting to Logic Pro and interacting with a MIDI Device Script. Because it's connecting to Logic Pro running on the same system as the application, the service and browser do not need to access anything else on the local network.
I'm creating the service and browser with calls like this:
err = DNSServiceRegister(
&serviceRef, 0,
kDNSServiceInterfaceIndexLocalOnly,
"MyService",
"_osc._udp",
"local",
nullptr,
52854,
txtLen,
txtRecord,
static_cast<DNSServiceRegisterReply>(myCallback), context
);
err = DNSServiceBrowse(
&browserRef, 0,
kDNSServiceInterfaceIndexLocalOnly,
"_osc._udp",
nullptr,
static_cast<DNSServiceBrowseReply>(browserCallback),
context
);
Despite the fact that I'm passing in kDNSServiceInterfaceIndexLocalOnly for the network interface, it still triggers an "Allow 'Application' to find devices on local networks?" permissions prompt.
How can I avoid that prompt?
It is both a significant failure point (in case users don't notice it or click 'Don't Allow' by mistake) but it may also scare them away, since it strongly implies my application is scanning devices on the local network, even though it's doing no such thing!
Hi,
I am trying to create an App which connects to a Device via Wifi and then has to do some HTTP Requests. Connecting to the Wifi is working properly but when I try to make an HTTP API Call I get the response that the Domain is unavailable (No Internet Connection). I created the App in Flutter on Android everything works perfectly. The packages are all iOS Compatible. But in Safari the URL works so it is probably a permission Issue. I have the Following permissions granted:
NSAppTransportSecurity
NSBonjourServices
NSLocalNetworkUsageDescription
I even have Multicast Networking
When I test the App I get asked to grant the access to local Network which I am granting.
I don´t know what I should do next can somebody help?
Feel free to ask for more Information
I'm creating a simple p2p server to advertise a service:
// server
let txtRecord = NWTXTRecord(["key": "value"])
NWListener.Service(name: name, type: "_p2p._tcp", domain: nil, txtRecord: txtRecord)
and client to look that service up:
// client
switch result.endpoint {
case let .service(name: name, type: type, domain: domain, interface: interface):
print(result.metadata)
The client is getting the advertisement ok, but metadata is nil. I expected to see a txt record there, is that not supported?
public let metadata: NWBrowser.Result.Metadata
/// Additional metadata provided to the browser by a service. Currently,
/// only Bonjour TXT records are supported.
Is the above server making a Bonjour TXT record or something else?
Basically what I want is to pass a short key/value data as part of advertisement.
Is There a Reliable Way to Check Local Network Permission Status in 2025?
I've read many similar requests, but I'm posting this in 2025 to ask:
Is there any official or reliable method to check the current Local Network permission status on iOS 18.x?
We need this to guide or navigate users to the appropriate Settings page when permission is denied.
Background
Our app is an IoT companion app, and Local Network access is core to our product's functionality. Without this permission, our app cannot communicate with the IoT hardware. Sadly, Apple doesn't provide any official API to check the current status of this permission.
This limitation has caused confusion for many users, and we frequently receive bug reports simply because users have accidentally denied the permission and the app can no longer function as expected.
Our App High Level Flow:
1. Trigger Permission
We attempt to trigger the Local Network permission using Bonjour discovery and browsing methods. (see the implementation)
Since there's no direct API to request this permission, we understand that iOS will automatically prompt the user when the app makes its first actual attempt to communicate with a local network device.
However, in our case, this creates a problem:
The permission prompt appears only at the time of the first real connection attempt (e.g., when sending an HTTP request to the IoT device).
This results in a poor user experience, as the request begins before the permission is granted.
The first request fails silently in the background while the permission popup appears unexpectedly.
We cannot wait for the user's response to proceed, which leads to unreliable behavior and confusing flows.
To avoid this issue, we trigger the Local Network permission proactively using Bonjour-based discovery methods. This ensures that the system permission prompt appears before any critical communication with the IoT device occurs.
We’ve tried alternative approaches like sending dummy requests, but they were not reliable or consistent across devices or iOS versions. (see the support ticket)
2. Wi-Fi Connection:
Once permission is granted, we allow the user to connect to the IoT device’s local Wi-Fi.
3. IoT Device Configuration:
After connecting, we send an HTTP request to a known static IP (e.g., 192.168.4.1) on the IoT network to configure the hardware.
I assume this pattern is common among all Wi-Fi-based IoT devices and apps.
Problem:
Even though we present clear app-level instructions when the system prompt appears, some users accidentally deny the Local Network permission. In those cases, there’s no API to check if the permission was denied, so:
We can’t display a helpful message.
We can’t guide the user to Settings → Privacy & Security → Local Network to re-enable it.
The app fails silently or behaves unpredictably.
Developer Needs:
As app developers, we want to handle negative cases gracefully by:
Detecting if the Local Network permission was denied
Showing a relevant message or a prompt to go to Settings
Preventing silent failures and improving UX
So the question is:
What is the current, official, or recommended way to determine whether Local Network permission is granted or denied in iOS 18.x (as of 2025)?
This permission is critical for a huge category of apps especially IoT and local communication-based products. We hope Apple will offer a better developer experience around this soon.
Thanks in advance to anyone who can share updated guidance.
I have an iPad app that uses Network framework to allow iPads to wirelessly communicate via their built-in ad hoc network capability. However, our app is used in an enterprise environment and there's concern about them communicating wirelessly, so I've been tasked with looking into wired communication.
Question:
I've read that iOS can connect to a wifi network using an Ethernet adapter, but would this work for ad hoc networking? For ex, if I connect 2 iPads via Ethernet cables to each other (not to the wifi router), and have the NWListener start broadcasting itself, can the NWBrowser find it and establish an ad-hoc connection via the Ethernet cables (and not the wireless cards inside the iPads). The iPads don't have any wifi connections established so they wouldn't be able to communicate any other way.
My guess is no...though if they did connect, how would I know it has happening via the cables and not via the wireless ad hoc capability, because I'm guessing there's no way to turn off just the wireless part of the ad hoc feature? If you disable the wifi on an iPad, you're also disabling ad hoc, right?
I'm pretty sure there's no way to programmatically send data back and forth between iPads using a USB-C cable connection, so I'm trying to determine if Ethernet cables would work.
We are developing an IoT companion app that connects to the IoT device's Wi-Fi network and communicates with it through local network APIs.
To support this functionality, we have:
Added the necessary keys in the Info.plist.
NSLocalNetworkUsageDescription ,
NSBonjourServices
Used a Bonjour service at app launch to trigger the local network permission prompt.
Problem on iOS 18.x (including 18.6 beta)
Even when the user explicitly denies the local network permission, our API communication still works.
This is unexpected behavior, as we assume denying permission should restrict access to local network communication.
We tested this with the latest iOS 18.6 beta (as per Thread 789461021), but the issue still persists.
This behavior raises concerns about inconsistent permission enforcement in iOS 18.x.
Problem on iOS 17.x
In iOS 17.x, if the user accidentally denies the local network permission and later enables it manually via Settings, the change does not take effect immediately.
The app cannot access the local network unless the device is restarted, which results in a confusing and poor user experience.
Expected Behavior
If local network permission is denied, local API communication should be strictly blocked.
If the permission is later enabled via Settings, the app should regain access without requiring a device restart.
Request
We request clarification and resolution on:
Why local network APIs are accessible even when permission is denied on iOS 18.x.
Whether the delayed permission update (requiring restart) in iOS 17.x is expected or a known issue.
Best practices to ensure consistent and predictable permission handling across iOS versions.
I've a iOT companion app, in which I'll connect to iOT's Wi-Fi and then communicate the device with APIs,
for the above functionality we needed local network permission So we enabled neccessary keys in info.plist and at the time of App Launch we trigger local network permission using the following code
info.plist
<string>This app needs local network access permission to connect with your iOT device and customize its settings</string>
<key>NSBonjourServices</key>
<array>
<string>_network-perm._tcp</string>
<string>_network-perm._udp</string>
</array>
Network Permission Trigger Methods
import Foundation
import MultipeerConnectivity
class NetworkPermissionManager: NSObject {
static let shared = NetworkPermissionManager()
private var session: MCSession?
private var advertiser: MCNearbyServiceAdvertiser?
private var browser: MCNearbyServiceBrowser?
private var permissionCallback: ((String) -> Void)?
func requestPermission(callback: @escaping (String) -> Void) {
self.permissionCallback = callback
do {
let peerId = MCPeerID(displayName: UUID().uuidString)
session = MCSession(peer: peerId, securityIdentity: nil, encryptionPreference: .required)
session?.delegate = self
advertiser = MCNearbyServiceAdvertiser(
peer: peerId,
discoveryInfo: nil,
serviceType: "network-perm"
)
advertiser?.delegate = self
browser = MCNearbyServiceBrowser(
peer: peerId,
serviceType: "network-perm"
)
browser?.delegate = self
advertiser?.startAdvertisingPeer()
browser?.startBrowsingForPeers()
// Stop after delay
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
self?.stopAll()
// If no error occurred until now, consider permission triggered
self?.permissionCallback?("granted")
self?.permissionCallback = nil
}
} catch {
permissionCallback?("error: \(error.localizedDescription)")
permissionCallback = nil
}
}
func stopAll() {
advertiser?.stopAdvertisingPeer()
browser?.stopBrowsingForPeers()
session?.disconnect()
}
}
extension NetworkPermissionManager: MCSessionDelegate {
func session(_: MCSession, peer _: MCPeerID, didChange _: MCSessionState) {}
func session(_: MCSession, didReceive _: Data, fromPeer _: MCPeerID) {}
func session(_: MCSession, didReceive _: InputStream, withName _: String, fromPeer _: MCPeerID) {}
func session(_: MCSession, didStartReceivingResourceWithName _: String, fromPeer _: MCPeerID, with _: Progress) {}
func session(_: MCSession, didFinishReceivingResourceWithName _: String, fromPeer _: MCPeerID, at _: URL?, withError _: Error?) {}
}
extension NetworkPermissionManager: MCNearbyServiceAdvertiserDelegate {
func advertiser(_: MCNearbyServiceAdvertiser, didReceiveInvitationFromPeer _: MCPeerID, withContext _: Data?, invitationHandler: @escaping (Bool, MCSession?) -> Void) {
invitationHandler(false, nil)
}
func advertiser(_: MCNearbyServiceAdvertiser, didNotStartAdvertisingPeer error: Error) {
print("❌ Advertising failed: \(error)")
if let nsError = error as NSError?, nsError.domain == NetService.errorDomain, nsError.code == -72008 {
permissionCallback?("denied")
} else {
permissionCallback?("error: \(error.localizedDescription)")
}
permissionCallback = nil
stopAll()
}
}
extension NetworkPermissionManager: MCNearbyServiceBrowserDelegate {
func browser(_: MCNearbyServiceBrowser, foundPeer _: MCPeerID, withDiscoveryInfo _: [String: String]?) {}
func browser(_: MCNearbyServiceBrowser, lostPeer _: MCPeerID) {}
func browser(_: MCNearbyServiceBrowser, didNotStartBrowsingForPeers error: Error) {
print("❌ Browsing failed: \(error)")
if let nsError = error as NSError?, nsError.domain == NetService.errorDomain, nsError.code == -72008 {
permissionCallback?("denied")
} else {
permissionCallback?("error: \(error.localizedDescription)")
}
permissionCallback = nil
stopAll()
}
}```
I want to satisfy this following cases but it's not working as expected
# Case1 Working
App launches --> trigger permission using above code --> user granted permission --> connect to iOT's Wi-Fi using app --> Communicate via Local API ---> should return success response
# Case2 Not working
App launches --> trigger permission using above code --> user denied permission --> connect to iOT's Wi-Fi using app --> Communicate via Local API ---> should throw an error
I double checked the permission status in the app settings there also showing disabled state
In my case case 2 is also return success, even though user denied the permission I got success response. I wonder why this happens
the same above 2 cases working as expected in iOS 17.x versions
Hi,
I am trying to update an old prototype I made for tvOS using DNSServiceBrowse(). The target was tvOS 17.
My old build from September 2023 still works fine: It can discover computers on the same local network as the Apple TV (simulator).
However, now that I am using Xcode 16, the DNSServiceBrowse() callback (of type DNSServiceBrowseReply) receives the error code: -65570.
The call to DNSServiceBrowse() itself returns no error, neither does the following call to DNSServiceProcessResult() — which actually triggers the call of the callback.
I found nowhere in the Internet any list of possible error codes received by the callback, so I have no idea what it means.
So, my first question is: What does this error code mean? (And is there any list of the possible errors somewehere, with their meaning?)
Since it was a prototype, I have no provisioning profile defined for it. Could that be related to the issue? Since I will make a real app out that prototype (targeting tvOS 18), I will have to define a provisioning profile for it.
Would a provisioning profile for the app solve the issue?
If yes, are there any requirements for that profile that I should take into account to solve the issue?
Thank you in advance for any help,
Marc
I'm using Network framework for communication between devices. The first time I instantiate an NWBrowser, it will prompt the user with a popup that says:
Allow <app name> to find devices on local networks?
The problem is, once I upgraded from Xcode 15.4 to Xcode 16.4, the popup doesn't appear; it says in the debug window:
nw_browser_fail_on_dns_error_locked [B1] nw_browser_dns_service_browse_callback failed: PolicyDenied(18,446,744,073,709,486,046)
I do have the info.plist keys Privacy-Local Network Usage Description (NSLocalNetworkUsageDescription) and Bonjour Services (NSBonjourServices) so it's not that.
Also, It still works on a real device.
I think something changed with Xcode 16 that tightened the security on a simulator, or maybe disabled Network framework entirely. It's not the firewall on my computer because that is turned off. I'm using an M1 MacBook Pro.
We have an iPad application that utilizes Multipeer Connectivity to enable local communication between devices running a copy of our app. Until recently, we were able to test this functionality in the Xcode simulator without any issues. We could easily set up multiple simulators and have them all communicate with each other. However, recently, either due to an upgrade to Xcode or MacOS, this functionality ceased working in the simulator. Surprisingly, it still functions perfectly on physical devices.
If we reboot the development computer and launch the simulator immediately after the reboot (without building and sending from Xcode, but running the existing code on the device), the issue resolves. However, the moment we generate a new build and send it to the simulator from Xcode, the multipeer functionality stops working again in the simulator. The simulators won’t reconnect until a reboot of the physical Mac hardware hosting the simulator.
We’ve tried the usual troubleshooting steps, such as downgrading Xcode, deleting simulators and recreating them, cleaning the build folder, and deleting derived data, but unfortunately, none of these solutions have worked. The next step is to attempt to use a previous version of MacOS (15.3) and see if that helps, but I’d prefer to avoid this if possible.
Does anyone have any obvious suggestions or troubleshooting steps that might help us identify the cause of this issue?
I am learning how to use DNS-SD from swift and have created a basic CLI app, however I am not getting callback results.
I can get results from cli. Something I am doing wrong here?
dns-sd -G v6 adet.local
10:06:08.423 Add 40000002 22 adet.local. FE80:0000...
dns-sd -B _adt._udp.
11:19:10.696 Add 2 22 local. _adt._udp. adet
import Foundation
import dnssd
var reference: DNSServiceRef?
func dnsServiceGetAddrInfoReply(ref: DNSServiceRef?, flags: DNSServiceFlags, interfaceIndex: UInt32, errorCode: DNSServiceErrorType, hostname: UnsafePointer<CChar>?, address: UnsafePointer<sockaddr>?, ttl: UInt32, context: UnsafeMutableRawPointer?) {
print("GetAddr'd")
print(hostname.debugDescription.utf8CString)
print(address.debugDescription.utf8CString)
}
var error = DNSServiceGetAddrInfo(&reference, 0, 0, DNSServiceProtocol(kDNSServiceProtocol_IPv6), "adet.local", dnsServiceGetAddrInfoReply, nil)
print("GetAddr: \(error)")
func dnsServiceBrowseReply(ref: DNSServiceRef?, flags: DNSServiceFlags, interfaceIndex: UInt32, errorCode: DNSServiceErrorType, serviceName: UnsafePointer<CChar>?, regType: UnsafePointer<CChar>?, replyDomain: UnsafePointer<CChar>?, context: UnsafeMutableRawPointer?) {
print("Browsed")
print(serviceName.debugDescription.utf8CString)
print(replyDomain.debugDescription.utf8CString)
}
error = DNSServiceBrowse(&reference, 0, 0, "_adt._udp", nil, dnsServiceBrowseReply, nil)
print("Browse: \(error)")
Foundation.RunLoop.main.run()
Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSLocalNetworkUsageDescription</key>
<string>By the Hammer of Grabthor</string>
<key>NSBonjourServices</key>
<array>
<string>_adt._udp.</string>
<string>_http._tcp.</string>
<string>_http._tcp</string>
<string>_adt._udp</string>
</array>
</dict>
</plist>
We're seeing an issue with bonjour services since macOS 15.4 onwards, specifically when running xcuitests on simulators that communicate with an app via bonjour services, the NWListener fails with -65555: NoAuth
Interestingly it only fails on subsequent iterations of the test, first iteration always succeeds.
The same code works fine on macOS 15.3.1 and earlier, but not 15.4 or 15.5.
Is this related to, or the same issue as here? https://developer.apple.com/forums/thread/780655
Also raised in feedback assistant: FB17804120
Hello,
I'm running into an issue while developing an iOS app that requires local network access. I’m using the latest MacBook Air M4 with macOS sequoia 15.5 and Xcode 16.1. In the iOS Simulator, my app fails to discover devices connected to the same local network.
I’ve already added the necessary key to the Info.plist:
NSLocalNetworkUsageDescription
This app needs access to local network devices.
When I run the app on a real device and M2 Chip Macbook's simulators, it works fine for local network permission as expected. However, in the M4 Chip Macbook's Simulator:
The app can’t find any devices on the local network
Bonjour/mDNS seems not to be working as well
I’ve tried the following without success:
Restarting Simulator and Mac
Resetting network settings in Simulator
Confirming app permissions under System Settings > Privacy & Security
Has anyone else encountered this issue with the new Xcode/macOS combo? Is local network access just broken in the Simulator for now, or is there a workaround?
Thanks in advance!
While trying to use Bonjour, i am encountering an issue. I was following the setup of Bonjour as described here: (https://developer.apple.com/forums/thread/735862)
the response is this :
nw_browser_fail_on_dns_error_locked [B2] nw_browser_dns_service_browse_callback failed: PolicyDenied(-65570)
browser did change state, new: waiting(-65570: PolicyDenied)
i tried modifying the info.plist to include
NSLocalNetworkUsageDescription and
NSBonjourServices but still getting the same
a workout or solution is much appreciated !
Hi folks, I'm building an iOS companion app to a local hosted server app (hosted on 0.0.0.0). The MacOS app locally connects to this server hosted, and I took the approach of advertising the server using a Daemon and BonjourwithTXT(for port) and then net service to resolve a local name. Unfortunately if there's not enough time given after the iPhone/iPad is plugged in (usb or ethernet), the app will cycle through attempts and disconnects many times before connecting and I'm trying to find a way to only connect when a viable en interface is available.
I've run into a weird thing in which the en interface only becomes seen on the NWMonitor after multiple connection attempts have been made and failed. If I screen for en before connecting it simply never appears. Is there any way to handle this such that my app can intelligently wait for an en connection before trying to connect? Attaching my code although I have tried a few other setups but none has been perfect.
func startMonitoringAndBrowse() {
DebugLogger.shared.append("Starting Bonjour + Ethernet monitoring")
if !browserStarted {
let params = NWParameters.tcp
params.includePeerToPeer = false
params.requiredInterfaceType = .wiredEthernet
browser = NWBrowser(for: .bonjourWithTXTRecord(type: "_mytcpapp._tcp", domain: nil), using: params)
browser?.stateUpdateHandler = { state in
if case .ready = state {
DebugLogger.shared.append("Bonjour browser ready.")
}
}
browser?.browseResultsChangedHandler = { results, _ in
self.handleBrowseResults(results)
}
browser?.start(queue: .main)
browserStarted = true
}
// Start monitoring for wired ethernet
monitor = NWPathMonitor()
monitor?.pathUpdateHandler = { path in
let hasEthernet = path.availableInterfaces.contains { $0.type == .wiredEthernet }
let ethernetInUse = path.usesInterfaceType(.wiredEthernet)
DebugLogger.shared.append("""
NWPathMonitor:
- Status: \(path.status)
- Interfaces: \(path.availableInterfaces.map { "\($0.name)[\($0.type)]" }.joined(separator: ", "))
- Wired Ethernet: \(hasEthernet), In Use: \(ethernetInUse)
""")
self.tryToConnectIfReady()
self.stopMonitoring()
}
monitor?.start(queue: monitorQueue)
}
// MARK: - Internal Logic
private func handleBrowseResults(_ results: Set<NWBrowser.Result>) {
guard !self.isResolving, !self.hasResolvedService else { return }
for result in results {
guard case let .bonjour(txtRecord) = result.metadata,
let portString = txtRecord["actual_port"],
let actualPort = Int(portString),
case let .service(name, type, domain, _) = result.endpoint else {
continue
}
DebugLogger.shared.append("Bonjour result — port: \(actualPort)")
self.resolvedPort = actualPort
self.isResolving = true
self.resolveWithNetService(name: name, type: type, domain: domain)
break
}
}
private func resolveWithNetService(name: String, type: String, domain: String) {
let netService = NetService(domain: domain, type: type, name: name)
netService.delegate = self
netService.includesPeerToPeer = false
netService.resolve(withTimeout: 5.0)
resolvingNetService = netService
DebugLogger.shared.append("Resolving NetService: \(name).\(type)\(domain)")
}
private func tryToConnectIfReady() {
guard hasResolvedService,
let host = resolvedHost, let port = resolvedPort else { return }
DebugLogger.shared.append("Attempting to connect: \(host):\(port)")
discoveredIP = host
discoveredPort = port
connectionPublisher.send(.connecting(ip: host, port: port))
stopBrowsing()
socketManager.connectToServer(ip: host, port: port)
hasResolvedService = false
}
}
// MARK: - NetServiceDelegate
extension BonjourManager: NetServiceDelegate {
func netServiceDidResolveAddress(_ sender: NetService) {
guard let hostname = sender.hostName else {
DebugLogger.shared.append("Resolved service with no hostname")
return
}
DebugLogger.shared.append("Resolved NetService hostname: \(hostname)")
resolvedHost = hostname
isResolving = false
hasResolvedService = true
tryToConnectIfReady()
}
func netService(_ sender: NetService, didNotResolve errorDict: [String : NSNumber]) {
DebugLogger.shared.append("NetService failed to resolve: \(errorDict)")
}
}
I'm using NWBrowser to search for a server that I hosted. The browser does find my service but when it tries to connect to it, it gets stuck in the preparing phase in NWConnection.stateUpdateHandler. When I hardcode the local IP address of my computer (where the server is hosted) into NWConnection it works perfectly fine and is able to connect.
When it gets stuck in the preparing phase, it gives me the warnings and error messages in the image below. You can also see that the service name is correct and it is found.
I have tried _http._tcp and _ssh._tcp types and neither work.
This is what my code looks like:
func findServerAndConnect(port: UInt16) {
print("Searching for server...")
let browser = NWBrowser(for: .bonjour(type: "_ssh._tcp", domain: "local."), using: .tcp)
browser.browseResultsChangedHandler = { results, _ in
print("Found results: \(results)")
for result in results {
if case let NWEndpoint.service(name, type_, domain, interface) = result.endpoint {
if name == "PocketPadServer" {
print("Found service: \(name) of type \(type_) in domain \(domain) on interface \(interface)")
// Construct the full service name, including type and domain
let fullServiceName = "\(name).\(type_).\(domain)"
print("Full service name: \(fullServiceName), \(result.endpoint)")
self.connect(to: result.endpoint, port: port)
browser.cancel()
break
}
}
}
}
browser.start(queue: .main)
}
func connect(to endpoint: NWEndpoint, port: UInt16) {
print("Connecting to \(endpoint) on port \(port)...")
// endpoint = NWEndpoint(
let tcpParams = NWProtocolTCP.Options()
tcpParams.enableFastOpen = true
tcpParams.keepaliveIdle = 2
let params = NWParameters(tls: nil, tcp: tcpParams)
params.includePeerToPeer = true
// connection = NWConnection(host: NWEndpoint.Host("xx.xxx.xxx.xxx"), port: NWEndpoint.Port(3000), using: params)
connection = NWConnection(to: endpoint, using: params)
connection?.pathUpdateHandler = { path in
print("Connection path update: \(path)")
if path.status == .satisfied {
print("Connection path is satisfied")
} else {
print("Connection path is not satisfied: \(path.status)")
}
}
connection?.stateUpdateHandler = { newState in
DispatchQueue.main.async {
switch newState {
case .ready:
print("Connected to server")
self.pairing = true
self.receiveMessage()
case .failed(let error):
print("Connection failed: \(error)")
self.isConnected = false
case .waiting(let error):
print("Waiting for connection... \(error)")
self.isConnected = false
case .cancelled:
print("Connection cancelled")
self.isConnected = false
case .preparing:
print("Preparing connection...")
self.isConnected = false
default:
print("Connection state changed: \(newState)")
break
}
}
}
connection?.start(queue: .main)
}
My laptop (M1 Pro, macOS 15.3.2) is connected to a dual stack network via Wi-Fi. The home.arpa. domain is supplied as a search domain via both DHCPv4 (options 15 and 119) and DHCPv6 (option 24). "Details…" for the network connection in System Settings show this domain under the DNS tab.
The laptop uses a Forwarding DNS Resolver of my router, which in turn forwards requests for home.arpa. (including subdomains) to a local DNS server (CoreDNS) which is authoritative for this zone.
The DNS server is configured via the following zone file:
$ORIGIN home.arpa.
$TTL 3600
@ IN SOA @ nobody.invalid. (1 3600 1200 604800 3600)
@ NS @
@ AAAA ….1
gateway A ….1
gateway AAAA …::1
b._dns-sd._udp PTR @
lb._dns-sd._udp PTR @
db._dns-sd._udp PTR @
_services._dns-sd._udp PTR _smb._tcp
_smb._tcp PTR Media._smb._tcp
Media._smb._tcp SRV 0 0 445 gateway
Media._smb._tcp TXT ("path=/media" "u=guest")
Output of dig(1) looks like:
$ dig @….1 -t PTR lb._dns-sd._udp.home.arpa.
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43291
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;lb._dns-sd._udp.home.arpa. IN PTR
;; ANSWER SECTION:
lb._dns-sd._udp.home.arpa. 1993 IN PTR home.arpa.
;; AUTHORITY SECTION:
home.arpa. 2771 IN NS home.arpa.
$ dig @….1 -t PTR _services._dns-sd._udp.home.arpa.
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9057
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;_services._dns-sd._udp.home.arpa. IN PTR
;; ANSWER SECTION:
_services._dns-sd._udp.home.arpa. 3600 IN PTR _smb._tcp.home.arpa.
;; AUTHORITY SECTION:
home.arpa. 3600 IN NS home.arpa.
$ dig @….1 -t PTR _smb._tcp.home.arpa.
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44220
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;_smb._tcp.home.arpa. IN PTR
;; ANSWER SECTION:
_smb._tcp.home.arpa. 3599 IN PTR Media._smb._tcp.home.arpa.
;; AUTHORITY SECTION:
home.arpa. 3599 IN NS home.arpa.
$ dig @….1 -t SRV Media._smb._tcp.home.arpa.
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 45878
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;Media._smb._tcp.home.arpa. IN SRV
;; ANSWER SECTION:
media._smb._tcp.home.arpa. 3600 IN SRV 0 0 445 gateway.home.arpa.
;; AUTHORITY SECTION:
home.arpa. 3600 IN NS home.arpa.
$ dig @….1 -t A gateway.home.arpa.
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2782
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;gateway.home.arpa. IN A
;; ANSWER SECTION:
gateway.home.arpa. 86400 IN A 192.168.99.1
;; AUTHORITY SECTION:
home.arpa. 3578 IN NS home.arpa.
$ dig @….1 -t AAAA gateway.home.arpa.
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17297
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;gateway.home.arpa. IN AAAA
;; ANSWER SECTION:
gateway.home.arpa. 3600 IN AAAA fd6f:9784:5753::1
;; AUTHORITY SECTION:
home.arpa. 3600 IN NS home.arpa.
Output of dns-sd(1):
/usr/bin/dns-sd -test
…
Testing for error returns when various strings are > 63 bytes: PASSED
Running basic API input range tests with various pointer parameters set to NULL:
Basic API input range tests: PASSED
$ dns-sd -m -F
Looking for recommended browsing domains:
DATE: ---Fri 11 Apr 2025---
8:50:17.846 ...STARTING...
Timestamp Recommended Browsing domain
8:50:17.847 Added (More) local
8:50:17.847 Added arpa
- > home
$ dns-sd -B _smb._tcp home.arpa.
Browsing for _smb._tcp.home.arpa.
DATE: ---Fri 11 Apr 2025---
8:59:10.044 ...STARTING...
$ dns-sd -L Media _smb._tcp home.arpa.
Lookup Media._smb._tcp.home.arpa.
DATE: ---Fri 11 Apr 2025---
9:15:53.328 ...STARTING...
$ dns-sd -Q _smb._tcp.home.arpa. PTR IN
DATE: ---Fri 11 Apr 2025---
9:16:52.208 ...STARTING...
Timestamp A/R Flags IF Name Type Class Rdata
9:16:52.210 Add 40000002 0 _smb._tcp.home.arpa. PTR IN 0.0.0.0 No Such Record
9:16:52.222 Add 2 0 _smb._tcp.home.arpa. PTR IN 0.0.0.0 No Such Record
Similarly, when I open Finder->Network I see home.arpa but it's empty. Of interest is that on the DNS server side I see the following requests being made:
2025-04-11 09:03:15 container,info,debug [INFO] […]:56541 - 21555 "SOA IN _afpovertcp._tcp.home.arpa. udp 44 false 512" NXDOMAIN qr,aa,rd 112 0.000755089s
2025-04-11 09:03:15 container,info,debug [INFO] […]:56077 - 58266 "SOA IN _smb._tcp.home.arpa. udp 37 false 512" NOERROR qr,aa,rd 105 0.001012632s
2025-04-11 09:03:15 container,info,debug [INFO] […]:45274 - 45976 "SOA IN _rfb._tcp.home.arpa. udp 37 false 512" NXDOMAIN qr,aa,rd 105 0.000762339s
2025-04-11 09:03:15 container,info,debug [INFO] […]:54387 - 32090 "SOA IN _adisk._tcp.home.arpa. udp 39 false 512" NXDOMAIN qr,aa,rd 107 0.001058132s
2025-04-11 09:03:15 container,info,debug [INFO] […]:35855 - 51155 "SOA IN _tcp.home.arpa. udp 32 false 512" NOERROR qr,aa,rd 100 0.000664963s
I suppose that an attempt to locate services is made but it's unsuccessful and I'm not sure why.
What further debugging can I attempt?