我有一個GET服務調用,在接收到響應時我必須執行某些操作。AFNetwork中的DidReceiveData回調
據我所知,委託方法實際上在AFNetworking
中的塊只在請求完全或失敗時才通知。
隨着一點點的深入瞭解AFNetworking
,我發現AFURLConnectionOperation
得到回調
- (void)connection:(NSURLConnection __unused *)connection
didReceiveData:(NSData *)data;
現在,我的問題是,我怎麼能得到這個回調中,發起請求的類?
P.S.我累了發送NSNotification
使用NSNotificationCenter
,我確實收到通知。但是,由於多個同時發送請求被髮送到服務器,我無法區分哪個請求的響應是我被通知的。
編輯
我注意到,AFHTTPRequestOperation
從AFURLConnectionOpertaion
繼承所以我可能實現的NSURLConnectionDelegate
connection:didReceiveData
方法,但問題又是,我怎麼從那裏發出的回調。 :(
這是否幫助https://github.com/AFNetworking/AFNetworking/wiki/AFNetworking-FAQ - >「如何跟蹤上傳或下載進度?「 – Thorsten 2013-03-13 06:58:41
嗯....我爲我的應用程序使用'AFHttpClient'的實現。我將如何設置這些進度塊? – tGilani 2013-03-13 07:22:28
這樣的事情:NSMutableURLRequest * request = [httpClient requestWithMethod:@」GET「path :@「/ your_path.php」parameters:nil]; AFJSONRequestOperation * operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:blah failure:blah]; [操作setDownloadProgressBlock:^(NSInteger bytesRead,NSInteger totalBytesRead,NSInteger totalBytesExpectedToRead){ myProgressView.progress =(float)totalRead/totalExpected; }; [httpClient enqueueHTTPRequestOperation:operation]; – Thorsten 2013-03-13 07:36:11