From 03d28fee03dbcb0e0d0f0d0851158b77a10ea6cb Mon Sep 17 00:00:00 2001 From: Olivier Poitrey Date: Fri, 20 Sep 2013 10:46:35 -0700 Subject: [PATCH] Only use the runloop with timeout on iOS 5 (fix #497) --- SDWebImage/SDWebImageDownloaderOperation.m | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index b3bd3d0..89dc44f 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -70,10 +70,18 @@ } [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStartNotification object:self]; - // Make sure to run the runloop in our background thread so it can process downloaded data - // Note: we use a timeout to work around an issue with NSURLConnection cancel under iOS 5 - // not waking up the runloop, leading to dead threads (see https://github.com/rs/SDWebImage/issues/466) - CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10, false); + if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_5_1) + { + // Make sure to run the runloop in our background thread so it can process downloaded data + // Note: we use a timeout to work around an issue with NSURLConnection cancel under iOS 5 + // not waking up the runloop, leading to dead threads (see https://github.com/rs/SDWebImage/issues/466) + CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10, false); + } + else + { + CFRunLoopRun(); + } + if (!self.isFinished) { [self.connection cancel];