title: To close NSStream objects before resigning active
body: <p>I have an NSInputStream and NSOutputStream scheduled in a non-main-thread run loop.  I'm using CFStreamCreatePairWithSocketToHost.  The remote endpoint is an external device that communicates with the app with TCP over wifi.</p>
  
  <p>When applicationWillResignActive is called, I want to close these.  I want to be guaranteed that they will close, because another app may want to communicate with the same device, and the device only accepts one TCP connection.</p>
  
  <p>Additional information:</p>
  
  <p>It is a frequent occurrence in the context of this device that multiple apps may need to communicate with the device.</p>
  
  <p>I have tried using performSelector:onThread:withObject:waitUntilDone:
  (with waitUntilDone:YES) in applicationWillResignActive.  Sometimes this doesn't work, and in those cases it seems that the selector does not get called.</p>
  
  <p>My understanding is that I can't close the NSStream objects or destroy the task queue from the main thread.</p>
  
  <p>I can not change how the device receives connections.  It listens on one address/port for TCP connections, and allows only one connection (it doesn't multiplex connections by source port).</p>