简体   繁体   English

15次快速调用后,NSURLConnection委托仅获得一次connectionDidFinishLoading

[英]NSURLConnection delegate gets connectionDidFinishLoading only once after 15 rapid calls

I create 15 rapid requests using NSURLConnection 我使用NSURLConnection创建了15个快速请求

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:url delegate:callback];
[conn start];

The server receives all 15 requests and provides the appropriate response. 服务器接收所有15个请求并提供适当的响应。 But my delegate object receives only a single connectionDidFinishLoading: method call. 但是我的委托对象仅收到一个connectionDidFinishLoading:方法调用。

What could be the underlying cause? 可能是什么原因?

Try running the NSURLConnection on the main run loop: 尝试在主运行循环上运行NSURLConnection:

NSURLConnection * connection = [[NSURLConnection alloc] 
                            initWithRequest:request
                                   delegate:callback 
                           startImmediately:NO];

[connection scheduleInRunLoop:[NSRunLoop mainRunLoop] 
                      forMode:NSDefaultRunLoopMode];
[connection start];

Also, when using: 另外,使用时:

 [[NSURLConnection alloc] initWithRequest:url delegate:callback];

You don't need to call start as the connection has already been started. 您不需要呼叫start因为连接已经启动。 start is only needed when using initWithRequest:delegate:startImmediately: and passed NO to startImmediately . start时,才需要使用时initWithRequest:delegate:startImmediately:并通过NOstartImmediately

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM