1
Scenario: The app consumes data from a web service, so that the app does not get "locked" I added the task of downloading the data in a secondary trhead, according to the following code:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
//realize aqui o trabalho em background
dispatch_async(dispatch_get_main_queue(), ^{
//quando as operações em background forem concluídas, execute aqui o código na thread principal para atualização da tela, caso necessário
});
});
However, when the web service is down, the app is waiting for the server to reply, and after a while without the answer, iOS shuts down my app.
I wonder if there is a Design Pattern for this type of situation, where we can control how long the app will be waiting for server response, and inform iOS to end the data request process without having to close the app!
But can I determine the waiting time on the client side? Type determine that the request time to be completed successfully should be at least 30 seconds and then send a Uialert to the user that connection to the web service was not possible?
– Tiago Amaral
Yes, you can change the timeout time. Example: manager.requestSerializer.timeoutInterval = 120; The default value is 60 seconds. That is, if the request does not complete in 60 seconds, it will fail. To notify the user about the error, just show the alert in the error block.
– Rafael Leão
Thanks again @Rafaelleao I’ll try it and I’ll tell you if it worked!
– Tiago Amaral
Hello! @Rafaelleao I tried to use this example but returned an error without downloading any data. Can we chat using skype or stackoverflow chat? My Skype > [email protected] Thanks!
– Tiago Amaral
I managed to solve the problem... I had to add a code in the Afurlresponseserialization file. m in line 215: ,@"text/html",nil]; In the following method self.acceptableContentTypes = [Nsset setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",nil];
– Tiago Amaral
It worked! Thank you very much!
– Tiago Amaral
I have another question because I do not use Afnetworking much, but I will use it from here on, I will post the question, if you can answer already thank you in advance! rs Link to another question: http://answall.com/questions/39332/comort-dataos-para-web-service-usando-afnetworking
– Tiago Amaral