ASINetworkQueue without setting DownloadDestinationPath
-
14-07-2021 - |
Frage
I want to fetch multiple images from the server for which I wish to use the ASINetworkQueue
. I was wondering if setting the downloadDestinationPath using setDownloadDestinationPath:path
for ASIHTTPRequest
object is necessary. Is there a way to use ASINetworkQueue
without setting the DownloadDestinationPath? If so, how to go about it? Also what happens to the images once they are downloaded in the Documents directory. I do not wish to pile up all the images as my project involves extensive use of images.
Lösung
I used the tag
property of the ASIHTTPRequest object to set different tags for each of my request before adding them to the ASINetworkQueue object.
ASIHTTPRequest *request;
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[imageURLDictionary objectForKey:@"test1"]]];
request.tag=1;
[networkQueue addOperation:request];
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[imageURLDictionary objectForKey:@"test2"]]];
request.tag=2;
[networkQueue addOperation:request];
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[imageURLDictionary objectForKey:@"test3"]]];
request.tag=3;
[networkQueue addOperation:request];
[networkQueue go];
And on success and failure handled them in the delegate method.
- (void)imageFetchComplete:(ASIHTTPRequest *)request
{
if (request.tag==1) {
_image1.image=[UIImage imageWithData:request.responseData];
}
if (request.tag==2) {
_image2.image=[UIImage imageWithData:request.responseData];
}
if (request.tag==3) {
_image3.image=[UIImage imageWithData:request.responseData];
}
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow