Est-ce AFNetworking ont le soutien de semi-?
-
22-10-2019 - |
Question
Je suis en train d'enquêter sur AFNetworking
en remplacement de ASIHTTPRequest
, et remarque une absence totale d'informations sur si elle prend en charge les téléchargements fond / uploads.
Avec un objet ASIHTTPReqeust
, tout ce que vous avez à faire est [request setShouldContinueWhenAppEntersBackground:YES]
d'appel et la demande continuera en arrière-plan. Y at-il favorable dans AFNetworking
?
La solution
EDIT : Au AFNetworking 1.0RC1 , c'est un explicite fonction. AFURLConnectionOperation
a maintenant la méthode setShouldExecuteAsBackgroundTaskWithExpirationHandler:
, qui gère de manière transparente tout cela pour vous.
Il est une caractéristique implicite, donc je ne pensais pas vraiment à faire la publicité. Tout ce que vous aurez besoin de faire est:
- (void)applicationWillResignActive:(UIApplication *)application {
__block UIBackgroundTaskIdentifier backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:^(void) {
[application endBackgroundTask:backgroundTaskIdentifier];
[[YourRestClient sharedClient] cancelAllHTTPOperations];
}];
}
Ou, si vous gérez vos opérations dans votre propre NSOperationQueue
, juste -cancelAllOperations
ici à la place.