バックグラウンドで実行する必要があるタスクを実行したい。このタスクには、Web サービスの応答の解析が含まれます。時間がかかるので、これをバックグラウンドで実行したかったのです。以下は、バックグラウンドタスクを実行しようとしたコードです。
//**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];
しかし、上記の関数を呼び出すボタンをタップしても何も起こりません。私は他の答えを試しましたが、それでも解決策が得られません。誰が私がどこで間違ったのか教えてもらえますか。前もって感謝します。