local iOS Zeroconf Device vs. iOS simulator Zeroconf Visual Studio

Hello,

I am not exactly sure this is the right place to ask this since it involves Microsoft's Visual Studio, but because the problem I am having involves iOS I figured I would anyway.

Info:

I am trying to develop a cross-platform application using .NET Maui in Visual Studio. I am on a Windows machine pairing to a mac with Xcode installed, so I can build for iOS. My local device is an iPhone 13 running on iOS Version 17.5.1. The simulators I am using in Visual Studio are all iOS Version 17+. I am using the .NET NuGet package Zeroconf which should work for both iOS and Android (Repo:https://github.com/novotnyllc/Zeroconf). I also believe I have given the correct permissions for iOS in my Info.plist.

Problem:

The problem I am coming across is that when I build and run my application in one of the installed iOS Simulators and I go to scan for local devices it is able to come back with 80-100 devices that we want to find, but when I build and run it on my local device it comes back with nothing found. I had searched for similar problems that other people were having and found that iOS 17+ has some potential problems when it comes to searching for devices. Is this true? If someone can help me solve this issue between the simulator and local device I would greatly appreciate it.

If there is any other information that I can give to help with solving this problem please let me know.

Thanks!

Discovery Code:

    TimeSpan scanTime = TimeSpan.FromMilliseconds(2000);
    int retries = 4;
    int retryDelayMilliseconds = 2000;
    Action<IZeroconfHost> callback = null;
    CancellationToken cancellationToken = default;
    System.Net.NetworkInformation.NetworkInterface[] arrayofnics = NetworkInterface.GetAllNetworkInterfaces();
    int index = 0;

    for (int i = 0; i < arrayofnics.Length; i++)
    {
        // en0 is for iOS 0 is for android. 
        if (arrayofnics[i].Description.Equals("en0") || arrayofnics[i].Description.Equals("0"))
        {
            index = i;
            break;
        }
    }

    System.Net.NetworkInformation.NetworkInterface wifi = arrayofnics[index];

    System.Net.NetworkInformation.NetworkInterface[] netInterfacesToSendRequestOn = { wifi };

    IReadOnlyList<IZeroconfHost> results = null;

    IReadOnlyList<string> domains;

    var browseDomains = await ZeroconfResolver.BrowseDomainsAsync();
    domains = browseDomains.Select(g => g.Key).ToList();
    

    results = await ZeroconfResolver.ResolveAsync("_http._tcp.local.", scanTime, retries, retryDelayMilliseconds, callback, cancellationToken, netInterfacesToSendRequestOn);

Info.plist:

<key>NSLocalNetworkUsageDescription</key>
<string>This app requires local network access to discover devices.</string>
<key>NSBonjourServices</key>
<array>
	<string>_ipspeaker._tcp.local</string>
	<string>_ipspeaker._tcp.local.</string>
	<string>_ipspeaker._tcp.</string>
	<string>_http._tcp.local.</string>
	<string>_http._tcp.</string>
</array>
Answered by DTS Engineer in 797282022

Yeah, don’t do that. Apple platforms have a built-in mDNS responder and it’s important that you use it rather than bring your own. Specifically:

  • It saves memory.

  • It save network traffic.

  • It means you don’t need to apply for, and be granted access to, the multicast entitlement. See FAQ-3 in the Local Network Privacy FAQ.

I believe it’s that last point that’s causing the misbehaviour you’ve described.

Our mDNS responder supports a number of APIs. The lowest-level one, the DNS-SD API, is supported by mDNS responders on other platforms, so it’s likely you’ll be able to find a wrapper for it.

Share and Enjoy

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

Do you know whether this Zeroconf library talks to the system resolver? Or is it running its own mDNS stack?

Share and Enjoy

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

The library runs its own mDNS stack.

Accepted Answer

Yeah, don’t do that. Apple platforms have a built-in mDNS responder and it’s important that you use it rather than bring your own. Specifically:

  • It saves memory.

  • It save network traffic.

  • It means you don’t need to apply for, and be granted access to, the multicast entitlement. See FAQ-3 in the Local Network Privacy FAQ.

I believe it’s that last point that’s causing the misbehaviour you’ve described.

Our mDNS responder supports a number of APIs. The lowest-level one, the DNS-SD API, is supported by mDNS responders on other platforms, so it’s likely you’ll be able to find a wrapper for it.

Share and Enjoy

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

local iOS Zeroconf Device vs. iOS simulator Zeroconf Visual Studio
 
 
Q