Bonjour discovery with NetServiceBrowser not working in iOS

i am using NetServiceBrowser for descovering bonjour services but my app is calling only netBrowserServiceWillSearch delegate method and keep on searching the Bonjour service without ever finding or stoping.

class BonjourDiscovery :  NetServiceBrowserDelegate, NetServiceDelegate
{

let serviceBrowser = NetServiceBrowser()
    
    @objc func ListOfPrinter(){
        
        serviceBrowser.delegate = self
        serviceBrowser.searchForServices(ofType: "_printer._tcp", inDomain: "")
    }
    
    func netServiceBrowser(_ browser: NetServiceBrowser, didFind service: NetService, moreComing: Bool) {
        
        print("---------didFind: \(service.name)")
    }
    
    func netServiceBrowserDidStopSearch(_ browser: NetServiceBrowser) {
        print(#function)
    }
    
    func netServiceBrowser(_ browser: NetServiceBrowser, didNotSearch errorDict: [String : NSNumber]) {
        print(#function)
    }

    func netServiceBrowser(_ browser: NetServiceBrowser, didRemove service: NetService, moreComing: Bool) {
        print(#function)
    }
    
    func netServiceBrowserWillSearch(_ browser: NetServiceBrowser) {
        print(#function)
    }
}

info.plist -:

<!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>Looking for local tcp Bonjour service</string>
	<key>NSBonjourServices</key>
	<array>
		<string>_printer._tcp</string>
	</array>
</dict>
</plist>

i have tried diffrent things whatever i found on apple forum or stackOverFlow like adding local in inDomain ,replacing _printer._tcp with _printer._tcp. ,but nothing works so far

_printer._tcp is probably not the droid you’re looking for. Try _ipp._tcp.

IMPORTANT Bonjour lets you discover services not devices. You’re not browsing for a printer, you’re browsing for a printer that speaks a specific protocol. In your case, by browsing for _printer._tcp you’re saying that you want to talk to the printer via the old LPD protocol, and most modern printers don’t advertise that.

A good option is to prototype this stuff with the dns-sd command-line tool on your Mac. For example:

% dns-sd -B _ipp._tcp local.
Browsing for _ipp._tcp.local.
DATE: ---Wed 22 Mar 2023---
 9:09:38.086  ...STARTING...
Timestamp     A/R    Flags  if Domain   Service Type   Instance Name
 9:09:38.086  Add        3   6 local.   _ipp._tcp.     Darth Inker
 9:09:38.087  Add        2  25 local.   _ipp._tcp.     Darth Inker
^C

Oh, and NetServiceBrowser has been deprecated in favour of NWBrowser. If you’re writing new code, I encourage you to use that.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Bonjour discovery with NetServiceBrowser not working in iOS
 
 
Q