I have some existing working code which creates a peer-to-peer AWDL connection using NSNetService.
self.advertisingService = [[NSNetService alloc] initWithDomain:@"local." type:@"_http-alt._tcp" name:self.serviceName];
self.advertisingService.delegate = self;
self.advertisingService.includesPeerToPeer = true;
[self.advertisingService scheduleInRunLoop:self.runLoop forMode:NSDefaultRunLoopMode];
[self.advertisingService publishWithOptions:NSNetServiceListenForConnections];
Previously, self.runLoop
was always [NSRunLoop mainRunLoop]
. Now I am embedding this code in an application where the thread 1 does not offer a run loop. This means the above code no longer worked: I wouldn't even get the netServiceDidPublish:
delegate callback.
So instead I spawn an NSThread
, create a run loop manually and supply a reference to it here (self.runLoop
). This mostly works: now I correctly receive the netServiceDidPublish:
callback.
The problem is that I still never receive netService:didAcceptConnectionWithInputStream:
when a connection occurs. Over on the connecting device, it is successfully obtaining the input and output streams and reaching the "Open" state for both. This new connection is never reflected here on the listening service.
It feels likely that I have to tell something else to use the custom runloop but I can't tell what. Does anyone have any ideas?