J'utilise AFNetworking 3.0
. J'ai téléchargé les tâches avec succès en utilisant la session d'arrière-plan. Maintenant, je veux suspendre et reprendre toutes les tâches basées sur la disponibilité du réseau. Comme suspendre des tâches quand aucun réseau et reprendre la tâche lors de la reconnexion réseau.Reprendre toutes les tâches de téléchargement lorsque le réseau se reconnecte à AFNetworking
code:
static AFURLSessionManager *manager;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"wts.Demo-Upload"];
sessionConfiguration.HTTPMaximumConnectionsPerHost = 20;
manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:sessionConfiguration];
});
[manager setDidFinishEventsForBackgroundURLSessionBlock:^(NSURLSession * _Nonnull session) {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.backgroundSessionCompletionHandler) {
void (^completionHandler)() = appDelegate.backgroundSessionCompletionHandler;
appDelegate.backgroundSessionCompletionHandler = nil;
completionHandler();
}
NSLog(@"All tasks are finished");
}];
NSOperationQueue *operationQueue = manager.operationQueue;
[manager.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusNotReachable:
// we need to notify a delegete when internet conexion is lost.
// [delegate internetConexionLost];
NSLog(@"No Internet Conexion");
break;
case AFNetworkReachabilityStatusReachableViaWiFi:
NSLog(@"WIFI");
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
NSLog(@"3G");
break;
default:
NSLog(@"Unkown network status");
[operationQueue setSuspended:YES];
break;
}
}];
[manager.reachabilityManager startMonitoring];
https://stackoverflow.com/questions/22197630/ios-reachability-notification-in-background/44236311#44236311 –