您的位置:首页 > 其它

NSURLConnection 不响应Delegate方法

2015-09-22 19:01 295 查看
有时会出现不响应的时候,解决方法就是为这个线程开启一个runloop使它始终处于运行状态

//设置请求超时时间为30s
NSMutableURLRequest *requestLoad = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://box.zhangmen.baidu.com/bdlrc/93/9351.lrc"] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];

self.connection = [[NSURLConnection alloc] initWithRequest:requestLoad delegate:self];
//开启一个runloop,使它始终处于运行状态

UIApplication *app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
finished = NO;
while (!finished)
{
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: