0

I have a problem. I call some method in dispatch_async. But in callMethod2 in different object I am uploading image with [NSURLConnection sendAsynchronousRequest. But after upload, It doesn't show me response. (However when I call callMethod2 without dispatch_async, it works great). Where can be the problem?

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
    [offline callMethod1];
    [offline callMethod2];
});

Upload image

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {

    NSLog("Never show me me this log");

}];
Patrik Dendis
  • 313
  • 6
  • 20
  • i think becuase you call this method from another queue and in implementation of method2 you use asynchronous method (so it call from another thread) , I recommend you get out call method 2 from dispach async. – Mo Farhand Jul 21 '15 at 20:49
  • `NSURLConnection sendAsynchronousRequest` is already async, move your '[offline callMethod1];' && `[offline callMethod2];` out of the `dispatch_async(dispatch_get_global_queue()}];` dont worry it wont block the main thread.. – 0yeoj Jul 22 '15 at 04:48

1 Answers1

1

You're calling NSLog on a thread that isn't the main thread (aka calling it asynchronously) so you won't see NSLog as it must run on the main thread.

You can have the completion block notify you some other way when it's done. The best way I've found is using https://github.com/kseebaldt/deferred which allows you to send a promise saying (I promise I'll do this thing and notify you when it's done).

Justin
  • 1,318
  • 9
  • 12