2013-08-04 28 views
0

我使用AFImageRequestOperation從我的服務器下載數百個jpg。取消AFImageRequestOperation中的所有操作

NSURLRequest *request = [NSURLRequest requestWithURL:theURL cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:20]; 
AFImageRequestOperation *operation; 
operation = [AFImageRequestOperation imageRequestOperationWithRequest:request 
               imageProcessingBlock:nil 
               success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {} 
               failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {} 
               ]; 

operation.outputStream = [NSOutputStream outputStreamToFileAtPath:[[paths objectAtIndex:0] stringByAppendingPathComponent:picture] append:NO]; 
[downloadQueue addOperation:operation]; 

如果我現在要取消正在進行的下載我執行[downloadQueue cancelAllOperations]

隨着AFNetworking的(今年年初)以前的版本,我用這個工作完美,但與最近我得到這個:

ERROR [http://myImageURL] -- The operation couldn’t be completed. (NSURLErrorDomain error -999.) 

所有未完成的操作。 我必須現在做一些額外的東西嗎?

+0

聽起來像是在最新版本中引入的錯誤。我可能會建議你在這裏提交一個問題:https://github.com/AFNetworking/AFNetworking/issues – Rob

回答

0

NSURLErrorDomain,該錯誤代碼定義如下:

kCFURLErrorCancelled = -999

...這是有道理的,因爲操作確實取消。這不是一個錯誤,而是一個預期的行爲。更改可能是對AFNetworking的記錄更改,或者是iOS版本之間的NSURLConnection中未記錄的更改。

+0

在AFURLConnectionOperation中操作的取消被處理,並且引發一個錯誤(cancelConnection正在調用didFailWithError)。如果這是想要的行爲,那我該如何抑制這個輸出呢?取消和失敗操作應該有所不同 – DanielR