Regarding resource loading, you can use AFNetworking to queue them.
You might be able to use the operation (void) enqueueHTTPRequestOperation: (AFHTTPRequestOperation *) AFHTTPClient.
First create a singleton to save your own AFHTTPClient as follows:
@interface CustomHTTPClient : NSObject + (AFHTTPClient *)sharedHTTPClient; @end @implementation CustomHTTPClient +(AFHTTPClient *)sharedHTTPClient { static AFHTTPClient *sharedHTTPClient = nil; if(sharedHTTPClient == nil) { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{
Then the queue of your requests is:
// Store the operations in case the failure block needs to cancel them __block NSMutableArray *operations = [NSMutableArray array]; // Add operations for url for (NSURL *url in urls) { NSURLRequest *request = [NSURLRequest requestWithURL:url]; __block AFHTTPRequestOperation *operation = [[CustomHTTPClient sharedHTTPClient] HTTPRequestOperationWithRequest:request success:^( AFHTTPRequestOperation *operation , id responseObject ){ // Do something } failure:^( AFHTTPRequestOperation *operation , NSError *error ){ // Cancel all operations if you need to for (AFHTTPRequestOperation* operation in operations) { [operation cancel]; } }]; [operations addObject:operation]; } for (AFHTTPRequestOperation* operation in operations) { [[CustomHTTPClient sharedHTTPClient] enqueueHTTPRequestOperation:operation]; }
There is also enqueueBatchOfHTTPRequestOperations: progressBlock: completionBlock: if you need to track progress.
AFNetworking Project: https://github.com/AFNetworking/AFNetworking/
AFNetworking Docs: http://afnetworking.org/Documentation/index.html
source share