[英]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. 我们正在为Android和iOS创建一个多平台应用程序。
Currently, we have a services that is published in Android with these information 目前,我们在Android中发布了包含这些信息的服务
Type:_http._tcp or _http._udp Name: abcController port 类型:_http._tcp或_http._udp名称:abcController端口
Now, I want to browse "abcController" services in iOS apps to get the list of host (ip) for connecting. 现在,我想浏览iOS应用程序中的“ abcController”服务以获取用于连接的主机(ip)的列表。 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. 但是,它仅调用netServiceBrowserWillSearch,并且没有任何响应。
Any helps is very appreciate ! 任何帮助都非常感谢!
您的服务名称必须以“ _”开头,否则会被混淆为域。
I found the solution for my issue. 我找到了解决我问题的方法。 It turns out that my service is published in udp, therefore.
原来,我的服务因此发布在udp中。 withthiscode.
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. 我现在可以得到服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.