iOS中Bonjour:NSNetServiceBrowser在子线程上使用
来源:互联网 发布:飞思卡尔竞赛编程软件 编辑:程序博客网 时间:2024/04/29 23:58
如果在子线程上创建一个NSNetServiceBrowser,并调用searchForServicesOfType开始搜索,发现不起作用。查看苹果的文档发现这么一段话:
A network service browser performs all searches asynchronously using the current run loop to execute the search in the background. Results from a search are returned through the associated delegate object, which your client application must provide. Searching proceeds in the background until the object receives a stop message.
To use an NSNetServiceBrowser object to search for services, allocate it, initialize it, and assign a delegate. (If you wish, you can also use thescheduleInRunLoop:forMode: and removeFromRunLoop:forMode: methods to execute searches on a run loop other than the current one.) Once your object is ready, you begin by gathering the list of accessible domains using either thesearchForRegistrationDomains or searchForBrowsableDomains methods. From the list of returned domains, you can pick one and use thesearchForServicesOfType:inDomain: method to search for services in that domain.
也就是说NSNetServiceBrowser是使用run loop实现不断循环搜索的,类似于NSTimer,主线程中默认开启了runloop,而子线程中默认没有创建runloop,所以需要自己创建并开启一个RunLoop,然后把NSNetServiceBrowser使用scheduleInRunLoop:forMode: 添加到runloop里,这样Bonjour才能开始工作。- iOS中Bonjour:NSNetServiceBrowser在子线程上使用
- iOS中Bonjour:NSNetServiceBrowser在子线程上使用
- ios之在子线程中使用定时器
- IOS在子线程中使用定时器,将定时器添加至RunLoop中(转)
- IOS在子线程中使用定时器,将定时器添加至RunLoop中
- IOS在子线程中使用定时器,将定时器添加至RunLoop中
- IOS在子线程中使用定时器,将定时器添加至RunLoop中
- IOS在子线程中使用定时器,将定时器添加至RunLoop中
- 如何在子线程中操作窗体上的控件
- 如何在子线程中操作窗体上的控件
- 如何在子线程中操作窗体上的控件
- 如何在子线程中操作窗体上的控件
- 如何在子线程中操作窗体上的控件
- 如何在子线程中操作窗体上的控件
- 在子线程中操作窗体上的控件
- 如何在子线程中操作窗体上的控件
- iOS 多线程初步研究-NSURLConnection在子线程中运行
- 安卓在子线程中使用使用Toast
- Android之开机自启动Service
- shell脚本中的数学运算
- properties的配置文件缓存模型
- ubuntu下使用curl查询本机公网ip
- leetcode 27 Remove Element
- iOS中Bonjour:NSNetServiceBrowser在子线程上使用
- 对activity的四种启动模式的理解
- dcmtk在PACS开发中的应用(基础篇) 作者:冷家锋 第三章 工作列表(Work List)(一)
- Android之广播大全 Intent Action 事件
- C++虚函数之虚表
- spring 注解总结
- 关于Block的一些初步认识
- Linux中awk -- 基础语法
- Spring mvc 无法使用EL表达式问题