用于 Web 查询的多个同时 NSConnects
使用异步下载方法和委托时,是否可以同时启动多个 nsconnection 并在每个查询完成时单独处理它们?或者,当您的代表收到每个查询的片段时,系统不会自动区分它们吗?在这种情况下,在每个连接通过代表进入时唯一标识每个连接的好方法是什么?
When using async download methods and delegates, is it possible to start multiple simultaneous nsconnections and handle them separately as each query completes? Or, will the system not automatically distinguish between them as your delegates receive pieces from each query? In which case, what would be a good approach to identify each connection uniquely as it enters through the delegates?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
系统不会自动区分
NSURLConnections
,而是调用的每个委托方法都会精确指定相关连接。例如:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
连接是
connection
。这样你就可以设置多个 NSURLConnection 并做出相应的反应。我个人将 NSURLConnection 对象设置为 ivars 并测试委托方法中的相等性,因为使用委托,您将需要从不同的方法访问数据容器。
您可以在优秀的 URL 加载系统编程指南。
The system won't automatically distinguish the
NSURLConnections
, instead, each delegate methods called is precising the concerned connection.For example :
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
the connection is
connection
. This way you can set severalNSURLConnection
s and react accordingly.I personnaly set
NSURLConnection
objects as ivars and test for equality in delegate methods, because using delegate, you will need to access the data containers from different methods.You will find more information in the excellent URL Loading System Programming Guide from Apple.