objective c - Is it worth to run the HTTP request in a new thread? -


i made app in objective c receives , sends data server through http request. works fine when connect school's internet app freezes. figured wifi slow , thought of making new thread , throw in http request , keep thread alive until app done connectivity, not conflict main interface.

the problem i'm not quite familiar threads , want know if worth doing way.

facebook provides asynchronous, non-blocking api handling http requests. wanted able wait the http request to return result. specifically, posing event facebook , want know facebookeventid of event posted.

in order that, created variable “postrequestreturned” , set false. in post function, send request , block thread long “postrequestretured” false. point note here simple while loop resulted in blocking main thread , making application unable receive response facebook. instead, used runloop libraries in objective c, runloop loop thread enters , uses run event handlers in response incoming events. some documentations

wait code finish execution

https://developer.apple.com/library/mac/#documentation/cocoa/conceptual/multithreading/runloopmanagement/runloopmanagement.html

the code snippet used

while(!postrequestreturned){  [[nsrunloop currentrunloop] runmode:nsdefaultrunloopmode beforedate:[nsdate distantfuture]];  } 

in completion handler facebook request, set postrequestreturned variable true.

courtesy: wait http request finish in obejective-c ios


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -