/// <summary> /// Xamarin.iOS only: returns the list of NSBonjourServices from Info.plist /// </summary> /// <param name="domain">Optional domain (example: "local.") to append to each service; null = no domain appended; non-null must terminate with "."</param> /// <returns></returns> public static IReadOnlyList <string> GetiOSInfoPlistServices(string domain = null) { var serviceList = new List <string>(); #if __IOS__ if (UIDevice.CurrentDevice.CheckSystemVersion(14, 5) && !UseBSDSocketsZeroconfOniOS) { serviceList.AddRange(BonjourBrowser.GetNSBonjourServices(domain)); } #endif return(serviceList); }
static internal async Task <ILookup <string, string> > BrowseDomainsAsync(BrowseDomainsOptions options, Action <string, string> callback = null, CancellationToken cancellationToken = default(CancellationToken), System.Net.NetworkInformation.NetworkInterface[] netInterfacesToSendRequestOn = null) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (netInterfacesToSendRequestOn != null) { throw new NotImplementedException($"iOS NSNetServiceBrowser/NSNetService does not support per-network interface requests"); } var browseDomainProtocolList = BonjourBrowser.GetNSBonjourServices(); ResolveOptions resolveOptions = new ResolveOptions(browseDomainProtocolList); var zeroconfResults = await ResolveAsync(resolveOptions, callback : null, cancellationToken, netInterfacesToSendRequestOn); List <IntermediateResult> resultsList = new List <IntermediateResult>(); foreach (var host in zeroconfResults) { foreach (var service in host.Services) { foreach (var ipAddr in host.IPAddresses) { IntermediateResult b = new IntermediateResult(); b.ServiceNameAndDomain = service.Key; b.HostIPAndService = $"{ipAddr}: {BonjourBrowser.GetServiceType(service.Value.Name, includeTcpUdpDelimiter: false)}"; resultsList.Add(b); // Simpleminded callback implementation if (callback != null) { callback(service.Key, ipAddr); } } } } ILookup <string, string> results = resultsList.ToLookup(k => k.ServiceNameAndDomain, h => h.HostIPAndService); return(results); }