Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios AF2.0比1.3慢_Ios_Performance_Batch Processing_Afnetworking 2 - Fatal编程技术网

Ios AF2.0比1.3慢

Ios AF2.0比1.3慢,ios,performance,batch-processing,afnetworking-2,Ios,Performance,Batch Processing,Afnetworking 2,在使用AFNetworking 1.3将我的应用升级到2.0之后,现在下载相同的文件似乎需要更长的时间。这是使用AFNetworking 1.3.x在批处理操作中下载4个文件的日志: 2014-03-21 19:29:23.775 <my_app>[2056:60b] 4 / 4 2014-03-21 19:29:23.777 <my_app>[2056:60b] 4 / 4 2014-03-21 19:29:23.778 <my_app>[2056:60b]

在使用AFNetworking 1.3将我的应用升级到2.0之后,现在下载相同的文件似乎需要更长的时间。这是使用AFNetworking 1.3.x在批处理操作中下载4个文件的日志:

2014-03-21 19:29:23.775 <my_app>[2056:60b] 4 / 4
2014-03-21 19:29:23.777 <my_app>[2056:60b] 4 / 4
2014-03-21 19:29:23.778 <my_app>[2056:60b] 4 / 4
2014-03-21 19:29:23.779 <my_app>[2056:60b] 4 / 4

嗯,我找到了一个解决方案,不是以前的工作方式,但我得到了更好的结果。变化在于,一个应用程序使用initWithBaseURL创建了一个AFHTTPRequestOperationManager实例,这似乎提高了请求的速度

AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:@"<url>"]];
[manager setResponseSerializer:[AFHTTPResponseSerializer new]];

for (id urlTemp in tempUrls){
    [manager GET:urlTemp parameters:nil success:^(AFHTTPRequestOperation *ro, id responseObject) {
        NSLog(@"Operation OK: %@", [ro.request URL]);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
}];
AFHTTPRequestOperationManager*管理器=[[AFHTTPRequestOperationManager alloc]initWithBaseURL:[NSURL URLWithString:@”“];
[manager setResponseSerializer:[AFHTTPResponseSerializer new]];
用于(临时URL中的id URLTEM){
[manager GET:urlTemp参数:无成功:^(AFHTTPRequestOperation*ro,id responseObject){
NSLog(@“操作正常:%@,[ro.request URL]);
}失败:^(AFHTTPRequestOperation*操作,NSError*错误){
NSLog(@“错误:%@”,错误);
}];

你试过几次了吗?这可能只是一次侥幸吗?@nycynik,是的,我试过很多次,结果总是一样的
NSMutableArray *tempOperations = [[NSMutableArray array] init];
NSArray *tempUrls = [[NSArray alloc] initWithObjects: obj1, obj2, obj3, obj4, nil];

for (id urlTemp in tempUrls){
    //Create NSURLRequest
    NSURL *url = [[NSURL alloc] initWithString:urlTemp];
    NSMutableURLRequest *finalrequest = [[NSMutableURLRequest alloc] initWithURL:url];

    // AFNetworking Request
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:finalrequest];
    [operation setResponseSerializer:[AFHTTPResponseSerializer new]];

    // Add request to array
    [tempOperations addObject:operation];
}

NSArray *operations = [AFURLConnectionOperation batchOfRequestOperations:tempOperations progressBlock:^(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations) {
    NSLog(@"%lu of %lu complete", numberOfFinishedOperations, totalNumberOfOperations);
} completionBlock:^(NSArray *operations) {
    for (AFHTTPRequestOperation *ro in operations) {

        if (ro.error) {

            NSLog(@"++++++++++++++ Operation error: %@", ro.error);

        }else {

            NSLog(@"Operation OK: %@", [ro.request URL]);

        }
    }
}];
[[NSOperationQueue mainQueue] addOperations:operations waitUntilFinished:NO];
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:@"<url>"]];
[manager setResponseSerializer:[AFHTTPResponseSerializer new]];

for (id urlTemp in tempUrls){
    [manager GET:urlTemp parameters:nil success:^(AFHTTPRequestOperation *ro, id responseObject) {
        NSLog(@"Operation OK: %@", [ro.request URL]);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
}];