1
votes

I need to find a way to observe when my app stops publishing the service via bonjour. This happens usually when the device receives a call or some such interruption.

Background:

I'm using GCDAsyncSocket to communicate between 2 devices in the same network for an app which plays music (supports playback in background).

I use NSNetService to broadcast the IP and port for the other apps (clients) to connect to the server.

When the server device receives a phone call, the publishing stops and other devices won't be able to see this service.

Is there some particular property I need to observe so that I know when it has stopped and I can restart again.

Thanks in advance

1

1 Answers

1
votes

Older question, but I'm facing the same problem currently.

As far as I know you can do the following:

You can use the NSNetServiceBrowser and the NSNetServiceBrowserDelegate delegate.

I assume you're already using the NSNetServiceBrowser class, with

[self.domainBrowser searchForServicesOfType:@"yourIdentifier" inDomain:@"local."];

You can set a delegate on your browser instance.

The delegate method - (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didRemoveService:(NSNetService *)aNetService moreComing:(BOOL)moreComing will be called when a NSNetService disappeared.

You can implement this method and do you needed operations.