Scenario, I have a data request using JSON but would like this request to be made outside of the main thread of the app so that it does not crash and that the user can perform other operations while the data is downloaded.
In the code below I can already download the data normally, but only need to be done on a secondary thread.
-(void)recebeTodosOsDadosPorFuncionarioDoWebService{
NSMutableString* strURL =[[NSMutableString alloc]initWithFormat:@"http://localhost/advphp/ArquivosFuncionando/pegaDadosNaoLidosPorFuncionario.php?funcionario=%@",funcionarioCadastrado];
NSURL* url = [NSURL URLWithString: strURL];
NSData* data = [NSData dataWithContentsOfURL:url];
NSError*erro;
arraySalvaDadosProcessos = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&erro];
if(arraySalvaDados == (id)[NSNull null]|| [arraySalvaDados count] == 0){
NSLog(@"Erro para receber dados do webservice: \n\n%@", arraySalvaDados);
}else{
[self salvaTodosOsDadosRecebidosNoBancoLocal];
}
}