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
the code snippet used
while(!postrequestreturned){ [[nsrunloop currentrunloop] runmode:nsdefaultrunloopmode beforedate:[nsdate distantfuture]]; } in completion handler facebook request, set postrequestreturned variable true.
Comments
Post a Comment