菜鸟教程小白 发表于 2022-12-12 16:25:51

objective-c - 使用 NSURLConnection 取消 NSOperation


                                            <p><p>我正在编写一个 <code>NSOperation</code> 来通过 <code>NSURLConnection</code> 发出 Web 服务请求。我想让 <code>NSOperation</code> 能够被取消,以便在必要时可以中断长时间运行的 HTTP 请求。如果我同步发出 HTTP 请求,它将阻塞线程并且我无法检查 <code>isCancelled</code> 提前终止。从 <code>NSOperation</code> 异步发出 HTTP 请求对我来说没有意义(委托(delegate)方法在哪里?)。最好的方法是什么?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我建议使用 <a href="http://allseeing-i.com/ASIHTTPRequest/" rel="noreferrer noopener nofollow">ASIHTTPRequest</a>对于这类问题。 <code>ASIHTTPRequest</code> 对象是 <code>NSOperation</code> 的子类,支持取消、自定义超时时间和阻塞。</p></p>
                                   
                                                <p style="font-size: 20px;">关于objective-c - 使用 NSURLConnection 取消 NSOperation,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/6205016/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/6205016/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: objective-c - 使用 NSURLConnection 取消 NSOperation