AFJSONRequestOperation 시리즈를 순서대로 실행하고 실패 할 경우 큐를 인터럽트 할 수 있습니다.AFJSONRequestOperation - 실패시 작업 큐를 인터럽트
가끔은 다음 작업에 시작할 기회가 있기 때문에 현재로서는 믿을 수 없습니다.
나는 나의 API를 엔드 포인트
AFJSONRequestOperation *lastOperation; // Used to add dependency
NSMutableArray *operations = [NSMutableArray array]; // Operations stack
AFAPIClient *httpClient = [AFAPIClient sharedClient];
[[httpClient operationQueue] setMaxConcurrentOperationCount:1]; // One by one
를 호출 싱글을 그리고 가끔 작동 여전히 기회를 얻을 실패 한 다음, 작업을
NSMutableURLRequest *request = ...; // define request
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
// Takes care of success
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
[[httpClient operationQueue] setSuspended:YES];
[[httpClient operationQueue] cancelAllOperations];
}];
[push:operation addDependency:lastOperation];
[operations $push:operation]; // This is using ConciseKit
lastOperation = operation;
// Repeat with other operations
// Enqueue a batch of operations
[httpClient enqueueBatchOfHTTPRequestOperations:operations ...
문제는이 방법을 추가 시작한다.
그래서 최대 동시 작업 1 개와 종속성 체인을 갖는 것은 오류 콜백이 완전히 실행될 때까지 대기열에 대기하도록하는 것으로 충분하지 않은 것으로 보입니다.
이 작업을 수행하는 올바른 방법은 무엇입니까?
감사
음, 적어도 나는 왜 그런지 이해합니다. 어떤 종류의 편집이 될까요? – Nycen
감사. 나는 실제로이 접근법을 생각했지만 나머지 코드 덕분에 리팩토링이 상당히 의미가 있었고 시도하기에는 너무 게을 렀다는 것을 알았습니다 :) 이제 스레드 설명과 푸시 덕분에 작동합니다! – Nycen