AFNetWorking + Скачать изображения в очереди + ОТМЕНА
-
14-11-2019 - |
Вопрос
Мне нужно скачать очередь изображений. Сначала я создал свои операции, а затем добавьте их с помощью метода «enqueue» afnetworking.
У меня есть 2 проблемы: 1) У меня не было прогрессного бара, работающего на очередь (и у меня есть работа с пользовательской очередью операции) 2) Я не нашел решение, чтобы остановить очередь, когда хочу
Я создал первые операции на пакетные и добавлять тему в массиве:
while ((dict = [enumerator nextObject]))
{
NSMutableURLRequest *request = [[MyHTTPClient sharedClient] requestWithMethod:@"GET" path:@"ws/webapp/services/pull_image" parameters:dict];
AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:request
imageProcessingBlock:nil cacheName:nil
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image)
{
NSLog(@"image : %@", [image description]);
// process images
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error)
{
// manage errors
}];
[operations addObject:operation];
}
.
Тогда я снимаю операции:
[[MyHTTPClient sharedClient] enqueueBatchOfHTTPRequestOperations:operations
progressBlock:^(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations)
{
float percentDone = ((float)((int)numberOfCompletedOperations) / (float)((int)totalNumberOfOperations));
[delegate syncServicesController:self updateProgressView:percentDone];
}
completionBlock:^(NSArray *operations)
{
//
}];
.
Итак, загрузка прогресса не работает. Но я вижу прогресс NumberofComplencePerationserations ...?1,2,3,4,5 ... Нужно ли заставить обновление просмотра прогресса в главной ните?
И когда я пытался остановить сетевые задачи:
- (void)cancelAllRequests
{
[[MyHTTPClient sharedClient] cancelAllHTTPOperationsWithMethod:@"GET" path:@"ws/webapp/services/pull_image"];
}
.
Я не понимаю, как остановить очередь запросов ... это, похоже, что работает, но у меня есть эта ошибка: - [NSBLOCKOPERATION CHARECT]: Недознанный селектор, отправленный на экземпляр 0x16f54c70
Решение
These were actually just fixed in the last day or two :)
Go ahead and update to the latest version of master, which includes the following:
cc2115e469: Progress blocks now dispatch to main by default, just like all of the other completion blocks in AFNetworking. This should fix any issues around the UI not updating there.
cac44aeb34: Fixes that problem with NSBlockOperation
being sent request
. There was an incorrect assumption baked into cancelAllHTTPOperationsWithMethod:
that all operations were AFHTTPRequestOperation
. The only downside is that it will not handle your batched operations. For that, you can always iterate through httpClient.operationQueue.operations
and pick out the one you want.