1

In my class I create a CBUrlConnection:

urlConnection = [NSURLConnection connectionWithRequest:request delegate:self];
[urlConnection start];

but I don't get any response, these delegate methods are never invoked:

- (void)connection:(NSURLConnection *)connection didFinishLoadingData:(NSData *)data error:(NSError *)error
- (void)connection:(NSURLConnection *)connection didUpdateProgress:(CGFloat)percent
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

The request seems to be correct, the server url is surely correct, and the server is working correctly. What could be wrong ?

aneuryzm
  • 63,052
  • 100
  • 273
  • 488

2 Answers2

4

I've just fixed it... it was because the code wasn't running on the main thread.

For who might be interested I've solved with:

dispatch_sync(dispatch_get_main_queue(), ^{

});
aneuryzm
  • 63,052
  • 100
  • 273
  • 488
1

You can absolutely run an NSURLConnection from inside an NSOperation. The actual trick is that an NSURLConnection needs a run loop. See http://www.cocoaintheshell.com/2011/04/nsurlconnection-synchronous-asynchronous/ and https://stackoverflow.com/a/6238764/171933

  • Johannes
Community
  • 1
  • 1
Johannes Fahrenkrug
  • 42,912
  • 19
  • 126
  • 165