I want to perform a task that must run in the back ground. The task involves parsing the response of Web service. As it takes some time, i wanted this to run on back ground. Below is the code i tried to perform background task.
//**When a button is tapped this method will be called.**
dispatch_queue_t myQueue=dispatch_queue_create("My Queue", NULL);
dispatch_async(myQueue, ^{
[self getDataPetioleGraph];//**This will parse the webservice response and the output will be stored in a array for populating on tableview**
dispatch_async(dispatch_get_main_queue(), ^{
[tableViewObj reloadData];
});
});
-(void)getDataPetioleGraph{
NSString *soapContent=[NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
"<soap:Body>"
"<GetDataPetioleGraph xmlns=\"http://tempuri.org/\">"
"<Account_Number>%@</Account_Number>"
"</GetDataPetioleGraph>"
"</soap:Body>"
"</soap:Envelope>",@"38003"];
NSMutableURLRequest *request=[[[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:@"web service link is here"]] autorelease];
NSString *contentLength=[NSString stringWithFormat:@"%d",[soapContent length]];
[request addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"http://tempuri.org/GetDataPetioleGraph" forHTTPHeaderField:@"SOAPAction"];
[request addValue:contentLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[soapContent dataUsingEncoding:NSUTF8StringEncoding]];
getDPGConnection=[[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
[getDPGConnection start];
But when i tap the button that calls the above function, nothing happens. I have tried the other answers but still i am not getting the solution. can anyone tell me where i went wrong. Thanks in advance.