I am using the latest Swift documentation to write NetService, which am able to publish and search. But I am unable to remove service from the publisher. Not able to understand the role of RunLoop here. However, if I kill the app then service is getting removed.
This is the code am using to publish the service.
class ServicePublisher : NSObject {
var nsNetService : NetService!
init?(domain : String, type : String, name : String, port : Int32){
nsNetService = NetService(domain: domain, type: type, name: name, port: port)
if nsNetService == nil{
return nil
}
}
func publish() {
nsNetService.publish(options:NetService.Options.listenForConnections)
}
func setDelegate(delegate : NetServiceDelegate) {
nsNetService.delegate = delegate
}
func stop(){
nsNetService.stop()
}
}
nsNetService.stop() should stop the service and get it removed from the DNS SD. NetServiceBrowser is also able to detect the removal of service. My mistake was that I did not attached the UIButton with the function which was supposed to call stop() api and hence no service removal.