[英]Cancel remaining request when entering background
My app has many requests and they take time to finish. 我的应用程序有很多请求,它们需要一些时间才能完成。 When requesting, I press home button then the app enters background.
请求时,我按主页按钮,然后该应用程序进入后台。 I want cancel all requests so that when open the app again I can create new requests.
我想取消所有请求,以便再次打开应用程序时可以创建新请求。 How can I do it?
我该怎么做? Is there any standard way to do it or I'll have to cancel each service separately (ex. in willEnterBackground method)?
有什么标准方法可以执行此操作,否则我将不得不分别取消每个服务(例如,在willEnterBackground方法中)?
Instead of getting into the complexities of managing threads you could simply keep a reference to all your active NSURLConnections. 不必复杂地管理线程,您只需保留对所有活动NSURLConnections的引用即可。 In
applicationDidEnterBackground:
cancel them: 在
applicationDidEnterBackground:
取消它们:
for (NSURLConnection *connection in activeConnections) {
[connection cancel];
}
cancel all requests .check below Links 取消所有请求。检查以下链接
iOS any way to cancel all network requests iOS以任何方式取消所有网络请求
How to immediately force cancel an NSOperation with AFNetworking? 如何立即通过AFNetworking强制取消NSOperation?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.