From 1e56cc84c11a259aff817c054756995e95f1782f Mon Sep 17 00:00:00 2001 From: Joel Fischer Date: Mon, 9 Dec 2019 14:41:48 -0500 Subject: Only try to remove from run loop when we aren't closing * It will be implicitly removed when the stream is closed --- SmartDeviceLink/SDLIAPSession.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SmartDeviceLink/SDLIAPSession.m b/SmartDeviceLink/SDLIAPSession.m index 96844b3a7..c69efce6d 100644 --- a/SmartDeviceLink/SDLIAPSession.m +++ b/SmartDeviceLink/SDLIAPSession.m @@ -61,10 +61,12 @@ NS_ASSUME_NONNULL_BEGIN if (status1 != NSStreamStatusNotOpen && status1 != NSStreamStatusClosed) { [stream close]; + } else if (status1 == NSStreamStatusNotOpen) { + // It's implicitly removed from the stream when it's closed, but not if it was never opened. + // When the USB cable is disconnected, the app will will call this method after the `NSStreamEventEndEncountered` event. The stream will already be in the closed state but it still needs to be removed from the run loop. + [stream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; } - // When the USB cable is disconnected, the app will will call this method after the `NSStreamEventEndEncountered` event. The stream will already be in the closed state but it still needs to be removed from the run loop. - [stream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; [stream setDelegate:nil]; NSUInteger status2 = stream.streamStatus; -- cgit v1.2.1