简体   繁体   English

进入后台时取消剩余请求

[英]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];
}

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

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