iphone - long running REST API -


a backend api need connect takes 3-4 minutes return response. ios client seems timeout @ 60 seconds (which default), , can't figure out how extend time out.

i have tried set timeoutinterval nsurlrequest large number, , set connection: keep-alive header, have no luck. here code using, omitting api details:

nsurl *url = [nsurl urlwithstring:@"myapi"];  nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url];  [request sethttpmethod:@"post"];  nsstring *poststring = @"key1=val1&key2=val2..."; [request sethttpbody:[poststring datausingencoding:nsutf8stringencoding]];  request.timeoutinterval = 600.0f;  [request setvalue:@"keep-alive" forhttpheaderfield:@"connection"]; [request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"];  [nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue mainqueue] completionhandler:^(nsurlresponse *response, nsdata *data, nserror *error) {      nslog(@"data = %@", data); }]; 

no data returned , response header fields empty, though backend api still processing request.

i heard might need set called "sockettimout" interval socket knows keep connection open longer, not know set that.

rather trying extend timeout, better idea modify server architecture bit. have server kick 200 ok gets data, have processing done in background queue. create api call can use retrieve data , have ios app check @ regular intervals see if data has been processed. alternatively, use push notification let user/phone know when data done processing.

if happen using ruby on rails it's extremely easy set long-running processes happen on worker thread. take delayed_job ruby gem.

if reason cannot modify how server operates, try making sure api using doesn't have timeout set itself. can't think of reason ios ignoring the timeoutinterval you're setting, unless property read only. try using init method instead:

- initwithurl:cachepolicy:timeoutinterval: 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -