androidiostcpnsnetservicensnetservicebrowser

I have a service that is published in Android. How to browser it in iOS?


We are creating a multi-platform apps for both Android and iOS.
Currently, we have a services that is published in Android with these information
Type:_http._tcp or _http._udp Name: abcController port

Now, I want to browse "abcController" services in iOS apps to get the list of host (ip) for connecting. I'm trying to do it with these code

 NSString* servicesOfType = @"abcController._http._tcp.";
NSString* domain  = @"";

domainBrowser = [[NSNetServiceBrowser alloc] init];
[domainBrowser setDelegate:self];
[domainBrowser searchForServicesOfType:servicesOfType inDomain:domain];

However, it only calls netServiceBrowserWillSearch and doesn't have any response.

Any helps is very appreciate !


Solution

  • I found the solution for my issue. It turns out that my service is published in udp, therefore. withthiscode.

    - (void) initBrowsingServices
    {
        NSString* servicesOfType = @"_http._udp.";
        NSString* domain  = @"local";
    
    
       domainBrowser = [[NSNetServiceBrowser alloc] init];
       [domainBrowser setDelegate:self];
       [domainBrowser searchForServicesOfType:servicesOfType inDomain:domain];
    
       domains = [[NSMutableArray alloc] init];
    
       searching = NO;
    }
    

    I can receive my service now.