我正在调查 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 而是在这里。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top