0

I've got the tagged NSURLConnection subclass, and need to fetch Image data from multiple URL-s...The idea is clear to me, but i can't start the connection properly, so that data would append into its place... here i have:

- (IBAction)sophisticatedDownload {
    connectionDict = [[NSMutableDictionary dictionaryWithCapacity:news.count] retain];
    for (int i =0; i<news.count; i++) 
    {
          //init the tagged connection

             if (theConnection) {
                    self.imageData = [NSMutableData data];
                    [connectionDict setObject: imageData forKey: theConnection.connID];    
            } else {       
                    NSLog(@"Connection failed");
            }
    }
}


- (void)connection :(tagConnection *)connection didReceiveData:(NSData *)data {
[[connectionDict objectForKey:connection.connID] appendData:data];
}


- (void)connectionDidFinishLoading:(tagConnection *)connection {

NSLog(connection.connID); 

What should

Artem Sultan
  • 459
  • 4
  • 10

1 Answers1

0

You can get start you connection like this -

NSString *urlString = [NSString stringWithFormat:@"http://EnterYourURLHere"];
NSURL *URL = [NSURL URLWithString:urlString];
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc]init];
[urlRequest setURL:URL];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-type"];

NSURLConnection *urlConnection = [[NSURLConnection alloc]initWithRequest:urlRequest delegate:self];
if(!urlConnection)
{
    [[[UIAlertView alloc]initWithTitle:@"OOoopppssS !!" message:@"There is an error occured. Please check your internet connection or try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];
}

But this is not good approach to download multiple images. See NSURLConnection Download multiple images to download multiple images.

Community
  • 1
  • 1
TheTiger
  • 13,264
  • 3
  • 57
  • 82