NSURLConnection 延迟 5 秒 [英] NSURLConnection 5 seconds delay

查看:51
本文介绍了NSURLConnection 延迟 5 秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码向我的 api 发出请求:

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        
}];    
}

我的问题是,在 NSLog(@"complete") 之后,应用程序冻结了 5 秒.我该如何解决?

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

谢谢.

推荐答案

sendAsynchronousRequestqueue 参数是完成处理程序块被分派.如果您在完成中进行任何 UI 更新处理程序,那么您可能应该使用

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]

这篇关于NSURLConnection 延迟 5 秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆