2009-06-26 33 views
1

我使用ASINetworkQueue發送兩個請求,這兩個請求位於隊列中。 我的問題是,當 請求失敗/完成時,我無法收到通知。ASIHTTPRequest:在網絡隊列中接收來自幾個請求的代理

代碼:

[networkQueue cancelAllOperations]; 
    [networkQueue setShowAccurateProgress:YES]; 
    [networkQueue setUploadProgressDelegate:self.progressIndicator]; 
    [networkQueue setDelegate:self]; 
    [networkQueue setQueueDidFinishSelector:@selector(queueDidFinish)]; 


    NSURL *urlAttachment = [NSURL URLWithString:@"http://localhost/test1.xml"]]; 
    ASIFormDataRequest *requestFile = [[[ASIFormDataRequest alloc] initWithURL:urlAttachment] autorelease]; 
    [requestFile setFile:filePath forKey:@"attachment[test]"]; 
    [requestFile setDidFailSelector:@selector(test1WentWrong)]; 
    [requestFile setDidFinishSelector:@selector(test1Done)]; 
    [networkQueue addOperation:requestFile]; //queue is an NSOperationQueue 

    NSURL *url = [NSURL URLWithString:@"http://localhost/test2.xml"]]; 
    ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease]; 
    [request setPostValue:test.filename forKey:@"filename[test]" ]; 
    [request setDidFailSelector:@selector(test2WentWrong)]; 
    [request setDidFinishSelector:@selector(test2Done)]; 
    [networkQueue addOperation:request]; //queue is an NSOperationQueue 

    [networkQueue go]; 

test1WentWrong,test1Done,test2WentWrong,test2Done不叫。 儘管請求運行良好,並且queueDidFinish被調用。

回答

4

您需要設置各個請求的委託,而不是隊列。

基本上,如果在隊列上設置了didFinish和didFail選擇器,則會調用隊列的委託。如果你在請求中設置它們,那麼調用請求的委託(你也可以同時執行這兩個操作,在這種情況下,兩者都被調用)。

在你的情況下,如果你想爲兩個請求使用相同的委託,但didFail/didFinish使用不同的選擇器,我可以看到如果你沒有設置委託,就可以調用隊列的委託請求。也許我應該補充一點... :)

+0

本,非常感謝您的回答。我失明瞭;-)添加委託完美運作。感謝你提供如ASIHTTPRequest這樣的包裝。這是非常好的,方便使用。我喜歡。 – Stefan 2009-06-27 07:50:32

相關問題