iphone - AFNetworking 有后台支持吗?

标签 iphone ios asihttprequest afnetworking

我正在研究 AFNetworking 作为 ASIHTTPRequest 的替代品,并注意到完全没有关于它是否支持后台下载/上传的信息。

使用ASIHTTPReqeust 对象,您只需调用[request setShouldContinueWhenAppEntersBackground:YES],请求将在后台继续。 AFNetworking 对此有任何支持吗?

最佳答案

编辑:截至AFNetworking 1.0RC1 ,这是一个显式功能。 AFURLConnectionOperation 现在有方法 setShouldExecuteAsBackgroundTaskWithExpirationHandler:,它可以透明地为您管理所有这些。


这是一个隐含的功能,所以我真的没想过要宣传它。您需要做的就是:


- (void)applicationWillResignActive:(UIApplication *)application {
    __block UIBackgroundTaskIdentifier backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:^(void) {
        [application endBackgroundTask:backgroundTaskIdentifier];
        [[YourRestClient sharedClient] cancelAllHTTPOperations];
    }];
}

或者,如果您在自己的 NSOperationQueue 中管理您的操作,只需在此处使用 -cancelAllOperations 即可。

关于iphone - AFNetworking 有后台支持吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7800614/

相关文章:

iphone - 检测 iPhone 屏幕上的亮点/暗点

ios - 更改 UIPickerView 选择指示器的颜色

ios - Firebase .observeSingleEvent(:with:) method is retrieving cached/old data

objective-c - ASIHttprequest 与 Apache CXF Restful Web 服务

iphone - ios 7 从 navigationViewController 中删除 viewController

iphone - 如何将数组元素添加到已包含另一个数组值的 NSMutableArray?

ios - 如何将 2 个 detailTextLabels 添加到 Swift 中的单元格?

ios - 改变 Swift 中的 VC 问题。如何在标签栏 Controller 的 View 之间传递数据?

iphone - ASIHTTP请求重定向

ios - XCode - “' autorelease' 不可用 : not available in ARC mode”