I have a server and i get that response :
{"products": [
{
"product_id": "1170",
"name": "zzzz®",
"sort_order": 0,
"brand": "zzzas",
"product_category_id": "1090",
"location_ids": [
"1078"
],
"icon_url": "http://zzzzz.com/media/2502/zzzz.png",
"icon_date": "Wed, 07 Nov 2012 14:03:47 GMT",
"thumbnail_url": "http://zzzz.com/media/2591/zzdfs.png",
"thumbnail_date": "Wed, 07 Nov 2012 14:04:02 GMT"
},
{
"product_id": "1126",
"name": "ddddd®",
"sort_order": 1,
"brand": "dddsas",
"product_category_id": "1110",
"location_ids": [
"1095"
],
"icon_url": "http://zzzzz.com/media/2507/ddddd.png",
"icon_date": "Wed, 07 Nov 2012 14:03:48 GMT",
"thumbnail_url": "http://zzzzz.com/media/2596/sssds.png",
"thumbnail_date": "Wed, 07 Nov 2012 14:04:05 GMT"
}
]}
i'm using that code to parse the JSON
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"link"]]; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSDictionary *jsonDict = (NSDictionary *) JSON;
NSArray *products = [jsonDict objectForKey:@"products"];
[products enumerateObjectsUsingBlock:^(id obj,NSUInteger idx, BOOL *stop){
NSString *productIconUrl = [obj objectForKey:@"icon_url"];
}];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { NSLog(@"Request Failure Because %@",[error userInfo]); }];
[operation start];
How can i get all the icon_urls and assign them on a AFnetworking queue for serialized download. Some files are also pdfs or mp4 files in the response so i want all of them packed in an array as requests and one by one to download them.
I've searched for AFClient but could find any source code or an example usage.
You should follow the MVC architecture in your project. According to your json format follwoings are my suggestions to you.
So first you should have to create a Model name "Product". "Product" should have properties like your json data iconUrl,productId,productName,thumnailURL.
So please take a look below parsing code and fetch the products list first.
Now you have full product list.Then you iterate the list and download the image data using following code
You should be able to loop through your JSON using that to access each URL and add an asynchronous download for each.
It would be easy to do using a for loop.
I'd look at this example on AFNetworking's Github page.
You should be able to setup the download with an
AFHTTPRequestOperation
documented here.To set the request up you do something like this:
There may be a way to optimize some of this but that's the general idea.