Search code examples
objective-cnsurlsessionnsoperationqueue

NSURLSession takes too much time


I'm using NSURLSession to post a request. Although I'm setting queue to main queue still it takes too much time to respond

 NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig delegate:self delegateQueue:[NSOperationQueue mainQueue]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:LOGIN_SERVICE]];

[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPMethod:@"POST"];

NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request];

[dataTask resume];

There is a similar question but it has only one answer which is similar to what I'm doing. Anything that I'm missing ?


Solution

  • As you update question with code required, I will say nothing apparently here which make your request slow, few things as this is Network request, it will depend on different things like network speed, server response time. It would be worth while testing on different networks devices.