Search code examples
iosnsthreadnsstreamnsrunloopexternal-accessory

Should a Bluetooth-communicating NSStream require a separate thread?


Using ExternalAccessory to talk to a Bluetooth device, I'm using the input and output NSStreams supplied by EASession to send messages to it.

In Apple's EADemo example, it schedules both streams to the main thread's run loop. However, I have noticed that in many networking-related applications that use NSStreams developers prefer to create a separate thread to perform read/write operations and schedule the streams to the new thread's run loop.

For a Bluetooth device, should such behavior (creating a separate thread) be implemented or scheduling it to the main thread's run loop won't cause major blocking issues?


Solution

  • It is in general preferred to do as less as possible on main thread. I think EADemo does this on main thread as in context of small example it is applicable, but in context of big production application it is not.