ios - Calling NSURLConnection inside dispatch_async and reading didReceiveResponse in mainRunLoop in iPhone development -


First of all, it's random with me because this is my first iOS related question for SO.

Am I receiving feedback for the following methods

  - (zero) connection: (NSURLConnection *) connection was the reception: (NSURLResponse *) response {} < / Code> 

after calling it

  NSURLConnection * conn = [[NSURL connection alloted] initWithRequest: request representative: self]; [Schedule Schedule Infinite Loop: [NSRunLoop mainRunLoop] forMode: NSDefaultRunLoopMode]; [to start];  

one

  inside sender_sink ();  

but the connection method is not calling, but when I run NSURLConnection code out of dispatch_async I call this method,

What is the reason for this and how can I correct it? This is because the representative refers to self and self refers to the background thread but UIViewController is not the same class is?

Since you are making a connection to schedule in a loop and afterwards start, With the code> initWithRequest the startImmediately parameter is set to NO . Right now, you are starting the connection two times. And, more importantly, you are starting this before scheduling it in the main run loop.

To resolve this, specify NO as startImmediately :

  NSURLConnection * conn = [ [NSURLConnection alloc] initWithRequest: Request Rep: Auto Start Import: No]; [Schedule Schedule Infinite Loop: [NSRunLoop mainRunLoop] forMode: NSDefaultRunLoopMode]; [to start];  

By saying that, I do not need to send this code to everyone in the background queue (because initWithRequest runs asynchronously and somebody Only the time when I use the pattern above, since the time I use some custom NSOperation subclass (in which case, the above pattern is very useful) in your NSURLConnection is wrapping the request. But in this case, it is unnecessary.


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -