Multiple file uploads with UI locking in ios

I have an array containing different urls and a set of buttons, each link is assigned to each button. Clicking on the button loads the content in the url that is assigned to that particular button. User can press multiple buttons at the same time to perform multiple downloads at the same time. And at the same time, the user must have a position to navigate through other views so that the loading process does not have to block the UI. What would be the best and simplest way to implement this? Share your ideas. Thanks to


source to share

3 answers

Just enter the data asynchronously:

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
[NSURLConnection sendAsynchronousRequest:request 
                                   queue:[NSOperationQueue mainQueue] 
                       completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                           // The code here is executed when the response from the request comes back.
                           // The variable "data" will contain the response from the data.
                           // So you can do something like:
                           UIImage *anImage = [[UIImage alloc] initWithData:data]];




Luke, use AFNetworking or ASIHTTPRequest lib with asynchronous requests.



You can easily implement Asynchronous NSURLConnection

i.e. every time the user clicks on this button, you start an asynchronous connection to do your dirty work.

There are many examples. One of the easiest blog style examples to understand is Matt Gallagher's Cocoa Love. There is a link here.

The gist of the method are delegate methods that are easy to work with and you can grab every file you load inside them.

Don't be tempted by the synchronous-style mix, as it is not that flexible and you will be trying to make an easy solution to upload multiple files using this technique.



All Articles