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)
         {

         }
     }
 }];
4

1 回答 1

0

这可能意味着您的应用程序的其他部分正在长时间占用主线程的运行循环。在主线程(特别是主 NSOperation 队列)空闲之前,处理响应的代码无法运行。如果你的主线程忙于做其他事情——在 NSOperation 队列、主运行循环或主调度队列上工作——那么你的处理程序在完成之前不会开始运行。

请记住,iOS 设备比模拟器慢很多,因此模拟器中的快速操作在实际设备上可能需要更长的时间。

我强烈建议使用 Instruments 对您的应用程序(在设备上)进行时间分析,看看它在那段时间里做了什么,然后从那里开始。如果您看到明显的延迟,我怀疑您会很容易发现问题。

于 2016-06-04T03:24:05.000 回答