This is a good way do it:
dispatch_queue_t backgroundQueue = dispatch_queue_create("com.domai.queue", 0);
dispatch_async(backgroundQueue, ^{
int categoriaID = [[detalleDescription objectForKey:@"idEmpresa"] intValue];
NSString *string = [NSString stringWithFormat:@"%d", categoriaID];
NSLog(@"ID EMPRESA %@",string);
NSMutableString *ms = [[NSMutableString alloc]
initWithString:@"http://url.php?id="];
[ms appendString:string];
// URL request
NSLog(@"URL = %@",ms);
NSURLRequest *request =
[NSURLRequest requestWithURL:[NSURL URLWithString:ms]];
//URL connection to the internet
NSData *responseData = [[NSURLConnection alloc]
initWithRequest:request delegate:self];
NSLog(@"responseData= %@",responseData);//["34"]
//Parse JSON
NSMutableDictionary * json = [NSJSONSerialization
JSONObjectWithData:responseData
options: NSJSONReadingMutableContainers
error: &error];
NSString *labelValue = (NSString*) [json objectAtIndex:0];
dispatch_async(dispatch_get_main_queue(), ^{
//update your UIlabel dataLabel
dataLabel.text = labelValue;
});
});
You should make the request and return the JSON in a background thread, then update the UILabel in the main queue.