简体   繁体   中英

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 !

您的服务名称必须以“ _”开头,否则会被混淆为域。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM