objective c - download multiple files on iphone -


I want to download the file (s) from the web server.

Scenario: As the user selects the line (file name - users can select 1 or more files to download) and press download, I am getting the URL for each file ( All have different URLs) and paths in the array and the following are

  - (zero) for DownloadFile {(I int = 0; I & lt; [pathArray count]; i ++) {NSURL * fileURL = [NSURL fileURLWithPath: [pathArray objectAtIndex: I]]; NSString * ResultURL = [fileURL absoluteString]; NSURL * url = [[NSWRL Alok] initWithString: ResultURL]; NSMutableURLRequest * Request = [NSMutableURLRequest requestWithURL: URL cachePolicy: NSURLRequestReloadIgnoringCacheData timeoutInterval: 60.0]; Conn = [[NSURLConnection alloc] initWithRequest: Representative Representative: Self]; If (Kon) {NSLog (@ " Ansamayutebldeta data] is retained); Anselog (@ "Veblantai:% d", [Vebdeta length]); Daunlodtag = yes;} else {Anselog (@ "************* Connection is not done ************************************************************************************************************************** *) Connection didReceiveData: (NSData *) Data {NSLog (@ "************************************************************************) [WebDataApendData: Data]; NSLog (@ "WebLantai:% D:", [WebData Length]); N Selog (@ "************* data were also obtained a append ***********"); if (downloadTag == YES) {paths = NSSearchPathForDirectoriesInDomains ( NSDocumentDirectory, NSUserDomainMask, YES); Self.documentsDir = [[path objectAtIndex: 0] stringByAppendingPathComponent: @ "NewResult.zip"]; [[NSFileManager defaultManager] createFileAtPath: documentsDir content: zero attributes: zero]; NSFileHandle * file1 = [NSFileHandle FileHandleForUpdatingAtPath: documentsDir]; [File1 writeData: webData]; NSLog (@ "WebData:% d", [WebData Length]); [File1 closeFile]; }}   

If I am not using it for loop then just download a file, it works fine, but not for loop .... it really is for me It is important to solve this issue.

Thank you very much

You are using asynchronous download, but Representative is the same object for each download item, so all downloaded data can be attached to the same file. The way I do it is to be a small object (downloadquitum) that is representative for a single download. When you download any other file, you can create a new DownloadQueueItem and it handles everything


Edit:.

Q: Instead of putting me through my own I'm searching there, if there exist "NewResult.zip" then make "NewResult1.zip" And so on

  NSString * docDir = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex: 0]; NSString * filename = @ "NewResult.% @ zip to"; (int i = 0; i ++) {NSString * filename = null; if ( I == 0) {file name = [NSString stringWithFormat: file name, @ ""];} else {file name = [NSString stringWithForm at: filename, [NSString stringWithFormat: @ "% i", i]];} if (! [[NSFileManager defaultManager] Failaksists Attpath: filename]) {// Save the file. break;}}    

Comments