Can't schedule EASession in (non-main) run loop?



  • Howdy,

    I've inherited some code that communicates with an external accessory device using EASession (iOS only). The main app communications method is via sockets wirelessly; a separate 'comms' thread is spun off for handling all I/O streams.

    A part of the standard Objective C code for external accessory communications goes like this:

    ...

    [[session inputStream] setDelegate:self];
    [[session inputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
    [[session inputStream] open];
    

    ...

    The problem that I'm investigating is that 'currentRunLoop' doesn't work in our environment where the EASession is created on the comms thread. It does work if I change to 'mainRunLoop', but that should mean that the external accessory is now bridging the main (GUI) thread and the comms thread.

    I'm having trouble tearing down and recreating the EASession, and it looks like the sticking point is that I can't successfully 'removeFromRunLoop' during teardown. The iOS version of the app doesn't have trouble, but it only uses one thread (per iOS design principles).

    Of particular concern: do I need to kick off the event loop in my comms thread? The documentation I've read seems to suggest that it is automatically started when I call start() on the thread object, but other parts of the documentation suggest that I need to do more?

    Thanks,
    Alex


Log in to reply