我使用 NSURLConnection
创建 15 个快速请求
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:url delegate:callback];
[conn start];
服务器接收所有 15 个请求并提供适当的响应。但我的委托(delegate)对象仅接收一个 connectionDidFinishLoading:
方法调用。
可能是什么根本原因?
最佳答案
尝试在主运行循环中运行 NSURLConnection:
NSURLConnection * connection = [[NSURLConnection alloc]
initWithRequest:request
delegate:callback
startImmediately:NO];
[connection scheduleInRunLoop:[NSRunLoop mainRunLoop]
forMode:NSDefaultRunLoopMode];
[connection start];
此外,在使用时:
[[NSURLConnection alloc] initWithRequest:url delegate:callback];
您不需要调用start
,因为连接已经开始。仅当使用 initWithRequest:delegate:startImmediately:
并将 NO
传递给 startImmediately
时才需要 start
。
关于ios - NSURLConnection 委托(delegate)在 15 次快速调用后仅获得一次 connectionDidFinishLoading,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25038073/