afnetworking在使用for循环时区分Web服务调用

时间:2015-09-03 14:33:17

标签: ios objective-c web-services asynchronous afnetworking

我使用AFNetworking在for循环中调用web服务。 我想区分响应,即当前响应是针对当前索引还是其他索引。

AFHTTPRequestOperationManager对象是否有任何属性,以便我可以区分每个响应。

我需要根据响应对数组中的某个对象执行某些操作,因此我需要识别每个响应。

for (int i = 0; i < [array count]; i++) {
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    [manager.requestSerializer setValue:requestAuthorization forHTTPHeaderField:@"Authorization"];
    [manager.requestSerializer setValue:@"guest" forHTTPHeaderField:@"user_type"];
    [manager.requestSerializer setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
    [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [manager.requestSerializer setValue:[[[UIDevice currentDevice] identifierForVendor] UUIDString] forHTTPHeaderField:@"user_type"];
    [manager.requestSerializer setValue:[[UIDevice currentDevice] systemVersion] forHTTPHeaderField:@"device_os"];
    [manager.requestSerializer setValue:[[UIDevice currentDevice] systemName] forHTTPHeaderField:@"device_name"];
    [manager.requestSerializer setValue:@"ugx9gdispQMa6SwmwbWjz5ApDuqCfRENm2ATbCy6" forHTTPHeaderField:@"X-Parse-Application-Id"];
    [manager.requestSerializer setValue:@"AwwFiB7oEvYYZqAhPH0u9q8UozluVm110kVVrOHQ" forHTTPHeaderField:@"X-Parse-REST-API-Key"];
    [manager.requestSerializer setValue:@"guest" forHTTPHeaderField:@"user_type"];
    [manager GET:URL parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
         NSLog(@"JSON: %@", responseObject);                              
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
         NSLog(@"error code %ld",(long)[operation.response statusCode]);
         NSLog(@"Error: %@", error);
    }];
}

0 个答案:

没有答案