iphone download several files

Posted by Floo on Stack Overflow See other posts from Stack Overflow or by Floo
Published on 2010-05-17T14:10:58Z Indexed on 2010/05/17 15:00 UTC
Read the original article Hit count: 381

Filed under:
|

hi all ! 

In my app i need to download several plist. 

to download a plist i use the NSURLconnection 

in my code i use an UIAlertView with a UIActivityIndicator then when the download is finished i add a button to the alert to dismiss it. 

To download the plist i use somewhere in my code an NSURL set to the adresse where the plist is, next i set a NSURLRequest with the url cache policy and a timeout interval.  Then i set my NSMutableData to the NSURL connection with a NSURLRequest.  In the delegate didReceiveData: i append data to my mutable data object, in the didFailWithError: i handle error. And finaly in the connectionDidFinishLoading  i serialize my data to a plist so i can write to file my plist, and release my alertview. 

My problem is : how can i do if i have sevetal file to download because the connectionDidFinishLoading is called each time my NSURLConnection is finished but i want to release my UiAlert when everything is finished. But when the first plist is downloaded my code in the connectionDidFinishLoading will fire. 

here is my code : 

in the view did load : 

// set the UiAlert in the view did load  NSURL *theUrl = [NSURL URLWithString:@"http://adress.com/plist/myPlist.plist"]; NSURLRequest *theRequest = [NSURLRequest requestWithURL:theUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; self.plistConnection = [[ NSURLConnection alloc] initwithRequest:theRequest delegate:self startImmediatly:YES]; //plistConnection is a NSURLConnection - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {  [incomingPListData appendData:data]; }

-(void)connection:(NSURLConnection *)connectionDidFailWithError:(NSError *)error {

// handle error here  }

-(void)connectionDidFinisloading:(NSURLConnection *) connection {  NSPropertyListFormat format; NSString *serialErrorString; 

NSData *plist = [NSPropertyListSerialisation propertyListFromData:incomingPlistData mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&serialErrorString];

if (serialErrorString) {//error} else { // create path and write plist to path} // change message and title of the alert

so if i want todownload an another file  where do i put the request the connection and how can i tell the didFinishLoading to fire code when all my file are downloaded. 

thanks to all 

© Stack Overflow or respective owner

Related posts about iphone

Related posts about download