AFNetworking队列需要很长时间才能获得第一个请求

时间:2013-01-04 14:24:08

标签: objective-c ios afnetworking

我一直在使用AFNetworking库来处理我的所有Http请求,我的示例请求看起来像这样

AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:requestObj];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id   responseObject) {

        [dic setValue:operation forKey:@"operationObj"];
        [dic setValue:responseObject forKey:@"jsonData"];

        [requestedView performSelector:callBackFunction withObject:[NSNumber numberWithBool:YES] withObject:dic];

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        NSLog(@"Error resopnse => %@",error);

        [dic setValue:operation forKey:@"operationObj"];
        [dic setValue:error forKey:@"error"];

        [requestedView performSelector:callBackFunction withObject:[NSNumber   numberWithBool:YES] withObject:dic];
    }];

当我第一次发出Http请求时,操作队列需要很长时间才能启动,有时我会将0作为响应状态代码

但是一旦我尝试再次触发相同的请求,我就没有遇到任何问题。

我错过了什么吗?

先谢谢

1 个答案:

答案 0 :(得分:0)

我不确定您的请求是什么,但完成和成功块应该影响请求的开始时间。我通常使用这样的AFJSONRequestOperation

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    // Success
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
    // Failure
}];

[operation start];

根据我们看不到的[operation start]电话?