Answer the question
In order to leave comments, you need to log in
How to make multiple get requests at the same time in objective c?
Hello!
I am writing a weather program for myself. Now I ran into a problem when you need to get data about the current weather and a forecast for several days (and this is 2 different requests).
I make a request through AFNetworking
Here is the method itself that makes the request, depending on the parameters - this is a request for the weather now or a forecast + additional parameters are possible
-(void) getWeather : (NSDictionary*)options
url:(NSString*)url
onSuccess:(void(^)(City* city))success
onFailure:(void(^)(NSError *error, NSInteger stausCode))failure
{
NSMutableDictionary *param = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"metric",@"units",APPID,@"APPID", nil];
// add params
for (NSString *key in options) {
NSString *value = options[key];
NSLog(@"Value: %@ for key: %@", value, key);
param[key] = value;
}
NSString* requestURL =[NSString stringWithFormat:@"http://api.openweathermap.org/data/2.5/%@", url]; // weather or forcast
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:requestURL
parameters:param
success:^(NSURLSessionTask *operation, id responseObject) {
City * city = [[City alloc] initWithWeatherData:responseObject];
success(city);
}failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Error: %@", error);
}
];
}
@property (nonatomic, strong) WeatherClass *weather;
@property (nonatomic, strong) ForcastClass *forcast;
Answer the question
In order to leave comments, you need to log in
This one is... mazhna. This is a 100% accurate answer to the question asked.
PS Several requests are made either sequentially or in different threads. Nothing new has been invented in Objective C.
You will have to write your own code that will do what you need.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question