NSURLConnection 5 seconds delay

久未见 提交于 2019-12-25 03:08:42

问题


i have the following code to make requests to my api:

-(void)makeApiCall:(NSString *)function params:(NSDictionary *)params notificationName:(NSString *)notificationName
{    
NSURL *url = [NSURL URLWithString:kBaseUrl];

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
httpClient.parameterEncoding = AFFormURLParameterEncoding;

NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:[NSString stringWithFormat:@"%@/%@",kApiBaseUrl,function] parameters:params];


NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
    NSLog(@"complete");
//..My code        
}];    
}

My problem is that, after the NSLog(@"complete"), the app is frozen for 5 seconds.. How can i fix that?

Thanks.


回答1:


The queue parameter of sendAsynchronousRequest is the queue on which the completion handler block is dispatched. If you do any UI updates in the completion handler then you probably should call the method with

queue:[NSOperationQueue mainQueue]


来源:https://stackoverflow.com/questions/16938795/nsurlconnection-5-seconds-delay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!