AFNetworking是否有后台支持?
我正在研究AFNetworking
作为AFNetworking
的替代ASIHTTPRequest
,并且注意到它是否支持后台下载/上传的信息完全缺乏。
使用ASIHTTPReqeust
对象,您只需调用[request setShouldContinueWhenAppEntersBackground:YES]
,请求将在后台继续。 AFNetworking
有没有这方面的AFNetworking
?
编辑 :作为AFNetworking 1.0RC1 ,这是一个明确的function。 AFURLConnectionOperation
现在有方法setShouldExecuteAsBackgroundTaskWithExpirationHandler:
,它透明地为你pipe理所有这些。
这是一个隐含的function,所以我没有真正考虑广告。 所有你需要做的是:
- (void)applicationWillResignActive:(UIApplication *)application { __block UIBackgroundTaskIdentifier backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:^(void) { [application endBackgroundTask:backgroundTaskIdentifier]; [[YourRestClient sharedClient] cancelAllHTTPOperations]; }]; }
- (void)applicationWillResignActive:(UIApplication *)application { __block UIBackgroundTaskIdentifier backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:^(void) { [application endBackgroundTask:backgroundTaskIdentifier]; [[YourRestClient sharedClient] cancelAllHTTPOperations]; }]; }
或者,如果您在自己的NSOperationQueue
pipe理自己的操作,则可以使用-cancelAllOperations
。