@@ -95,7 +95,9 @@ - (void)start {
95
95
if (self.progressBlock ) {
96
96
self.progressBlock (0 , NSURLResponseUnknownLength);
97
97
}
98
- [[NSNotificationCenter defaultCenter ] postNotificationName: SDWebImageDownloadStartNotification object: self ];
98
+ dispatch_async (dispatch_get_main_queue (), ^{
99
+ [[NSNotificationCenter defaultCenter ] postNotificationName: SDWebImageDownloadStartNotification object: self ];
100
+ });
99
101
100
102
if (floor (NSFoundationVersionNumber ) <= NSFoundationVersionNumber_iOS_5_1) {
101
103
// Make sure to run the runloop in our background thread so it can process downloaded data
@@ -150,7 +152,9 @@ - (void)cancelInternal {
150
152
151
153
if (self.connection ) {
152
154
[self .connection cancel ];
153
- [[NSNotificationCenter defaultCenter ] postNotificationName: SDWebImageDownloadStopNotification object: self ];
155
+ dispatch_async (dispatch_get_main_queue (), ^{
156
+ [[NSNotificationCenter defaultCenter ] postNotificationName: SDWebImageDownloadStopNotification object: self ];
157
+ });
154
158
155
159
// As we cancelled the connection, its callback won't be called and thus won't
156
160
// maintain the isFinished and isExecuting flags.
@@ -216,8 +220,9 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespon
216
220
} else {
217
221
[self .connection cancel ];
218
222
}
219
-
220
- [[NSNotificationCenter defaultCenter ] postNotificationName: SDWebImageDownloadStopNotification object: nil ];
223
+ dispatch_async (dispatch_get_main_queue (), ^{
224
+ [[NSNotificationCenter defaultCenter ] postNotificationName: SDWebImageDownloadStopNotification object: nil ];
225
+ });
221
226
222
227
if (self.completedBlock ) {
223
228
self.completedBlock (nil , nil , [NSError errorWithDomain: NSURLErrorDomain code: [((NSHTTPURLResponse *)response) statusCode ] userInfo: nil ], YES );
@@ -340,7 +345,9 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)aConnection {
340
345
CFRunLoopStop (CFRunLoopGetCurrent ());
341
346
self.thread = nil ;
342
347
self.connection = nil ;
343
- [[NSNotificationCenter defaultCenter ] postNotificationName: SDWebImageDownloadStopNotification object: nil ];
348
+ dispatch_async (dispatch_get_main_queue (), ^{
349
+ [[NSNotificationCenter defaultCenter ] postNotificationName: SDWebImageDownloadStopNotification object: nil ];
350
+ });
344
351
}
345
352
346
353
if (![[NSURLCache sharedURLCache ] cachedResponseForRequest: _request]) {
@@ -377,7 +384,9 @@ - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)err
377
384
CFRunLoopStop (CFRunLoopGetCurrent ());
378
385
self.thread = nil ;
379
386
self.connection = nil ;
380
- [[NSNotificationCenter defaultCenter ] postNotificationName: SDWebImageDownloadStopNotification object: nil ];
387
+ dispatch_async (dispatch_get_main_queue (), ^{
388
+ [[NSNotificationCenter defaultCenter ] postNotificationName: SDWebImageDownloadStopNotification object: nil ];
389
+ });
381
390
}
382
391
383
392
if (self.completedBlock ) {
0 commit comments