NSOperationQueue完成

时间:2012-03-09 17:50:32

标签: objective-c ios asihttprequest

我正在使用ASIHTTPRequest发出队列请求,但我想知道是否有办法知道队列何时完成所有请求都是我的代码的一部分

 for (int i=0; i< [result count]; i++) 
{
    Reportes *temp    =   [result objectAtIndex:i];
    ASIFormDataRequest *request     =   [ASIFormDataRequest requestWithURL:url];

    [request setTag:0];
    [request setDelegate:self];
    [request setPostValue:[[NSUserDefaults standardUserDefaults] stringForKey:USERNAME] forKey:POST_USUARIO];
    [request setPostValue:[KeychainWrapper keychainStringFromMatchingIdentifier:PIN_SAVED] forKey:POST_CLAVE];
    [request setPostValue:POST_IDSISTEMA_VALUE forKey:POST_IDSISTEMA];
    [request setPostValue:[self getMacAddress] forKey:POST_MAC];

    [request setPostValue:[[temp toNSDictionary] JSONRepresentation] forKey:@"value"];
    [[self queue] addOperation:request];

} 

1 个答案:

答案 0 :(得分:2)

您可以实施以下方法

- (void)queueFinished:(ASINetworkQueue *)queue
{
    // You could release the queue here if you wanted
    if ([[self networkQueue] requestsCount] == 0) {
        [self setNetworkQueue:nil]; 
    }
    NSLog(@"Queue finished");
}

queueFinished是在所有请求完成后调用的那个。要使其工作,您必须致电

[[self queue] setQueueDidFinishSelector:@selector(queueFinished:)];

初始化队列时