NSURLConnection 的使用

编程知识 更新时间:2023-05-02 19:10:53

1.不能同时发起过多的请求,因为发起过多的话会导致请求超时,现在工程中同时工作的请求5个。

2.默认情况下在哪个线程发起的NSURLConnection,代理的回掉就会在哪个线程被回掉。

   如果是直接调用NSURLConnection的initWithRequest:delegate:startImmediately:(第三个参数用YES,这个是designated initializer)或者方法initWithRequest:delegate:时,NSURLConnection会默认运行在NSDefaultRunLoopMode模式下,即使再使用scheduleInRunLoop:forMode:设置运行模式也没有用。

3.可以有两个办法让NSURLConnection在子线程中运行,即将NSURLConnection加入到run loop或者NSOperationQueue中去运行。

- (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode; //将加入指定的run loop中运行,必须保证这时NSURLConnection不能启动,否则不起作用了

- (void)unscheduleFromRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode; //将取消在指定run loop中的运行,实际上就会停止NSURLConnection的运行


NSOperationQueue *queue = [[NSOperationQueueallocinit];

NSURLConnection *conn = [[NSURLConnection allocinitWithRequest:request delegate:self startImmediately:NO]; 

[conn setDelegateQueue:queue];




 

更多推荐

NSURLConnection 的使用

本文发布于:2023-04-28 04:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/974641834ac7ec2b9b048e167fa76979.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NSURLConnection

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 107765文章数
  • 27244阅读数
  • 0评论数