ASINetworkQueue is simply a subclass of NSOperationQueue , what it does is create a queue of Request objects, so for example, you can have 10 pending requests and visit 5 at a time when the request is completed, another request in the queue becomes active.
Having a request queue is certainly useful in your case, but you have not inserted any code, as you are dealing with requests right now. Therefore, I will give you a "general concept" on how to do this:
Firstly, I assume that you have already figured out how to determine when the user will download a song and have the file URL. If not, here is another related question . Also installed ASI .
Add an object that handles downloads, say, DownloadManager:
#import "ASINetworkQueue.h" #import "ASIHTTPRequest.h" @interface DownloadManager : NSObject <ASIHTTPRequestDelegate> { ASINetworkQueue *requestQueue; } + (DownloadManager*)sharedInstance; - (void)addDownloadRequest:(NSString*)URLString;
I will create this class as singleton ( based on this answer ) because I assume that you are working with a single load queue. If it is not, adapt it to your needs:
@implementation DownloadManager static DownloadManager *_shared_instance_download_manager = nil; + (DownloadManager*)sharedInstance { @synchronize { if (!_shared_instance_download_manager) { _shared_instance_download_manager = [[DownloadManager alloc] init]; } return _shared_instance_download_manager } } - (id)init { self = [super init]; if (self) { requestQueue = [[ASINetworkQueue alloc] init]; requestQueue.maxConcurrentOperationCount = 2; requestQueue.shouldCancelAllRequestsOnFailure = NO; } return self; } - (void)addDownloadRequest:(NSString*)URLString { NSURL *url = [NSURL URLWithString:URLString]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; request.delegate = self; [requestQueue addOperation:request]; [requestQueue go]; } - (void)requestFinished:(ASIHTTPRequest*)request {
With all this, now you can add download requests simply:
DownloadManager *manager = [DownloadManager sharedInstance]; [manager addDownloadRequest:MyUrl];
The first tab will add elements to the DownloadManager , the other tab should be listened to after the download is completed or the current state. I did not add this to the code as it depends on how you do it. This can be a custom delegate method (i.e. - (void)DownloadManager:(DownloadManager*)downloadManager didFinishDownloadRequest:(ASIHTTPRequest*)request ) or pass the current request delegate or use the NSNotificationCenter .