test.h
{
dispatch_queue_t backgroundQueue;
}
test.m
- (void)viewDidLoad
{
[super viewDidLoad];
//com.unique.uniqueidentifier.youtube is any unique name
backgroundQueue = dispatch_queue_create("com.unique.uniqueidentifier.youtube", NULL);
}
-(void)anyFunction
{
dispatch_async(backgroundQueue, ^(void){
[self sendRequestForData];
});
}
-(void)sendRequestForData
{
NSString *post = @"";
NSData *postData = [post dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:NO];
NSMutableURLRequest *urlRequest = [[[NSMutableURLRequest alloc] init] autorelease];
[urlRequest setURL:[NSURL URLWithString:<any url string for fetching data from server>]];
[urlRequest setHTTPMethod:@"GET"];
[urlRequest setHTTPBody:postData];
NSData *urlData;
NSURLResponse *response;
NSError *error;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
if(!urlData) {
NSLog(@"No connection!");
}else {
}
//Back To main thread
dispatch_async(dispatch_get_main_queue(), ^(void){
//Reload the data
[mtableview reloadData];
});
}
Comments
Post a Comment