0

NSString * strURL = [NSString stringWithFormat:@"%@action=getResForOffer&offerid=%@",SERVER_URL,strOfferID];

NSURL *url = [NSURL URLWithString:[strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:url];

[request setHTTPMethod:@"GET"];

[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
 {
     if (error)
     {
         NSLog(@"%@",error.description);
     }
     else
     {
         NSMutableArray * arrJsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

         NSLog(@"Json Data --> %@",arrJsonData);

         if (arrJsonData.count)
         {

         }
     }
 }];

1 Answers1

0

That probably means some other part of your app is tying up the main thread's run loop for an extended period of time. The code that handles the response can't run until the main thread (the main NSOperation queue, specifically) is idle. If your main thread is busy doing something else—doing work on that NSOperation queue, on the main run loop, or on the main dispatch queue—then your handler won't start running until it finishes.

Remember that the iOS device is a lot slower than the simulator, so things that are quick in the simulator can take a lot longer on the actual device.

I would strongly suggest using Instruments to do a time profile of your app (on the device) and see what it is doing during that time, and go from there. If you're seeing a noticeable delay, I suspect you'll find the problem pretty easily.

dgatwood
  • 10,129
  • 1
  • 28
  • 49