Closed danielmhanover closed 7 years ago
same error with me too, while adding multiple downloads in array. please help
or Can we limit downloader to download one by one at a time after placing it in queue, currently 3 items starts downloading.
Can you write down some steps how we can reproduce it?
loop through available downloads array and add them into download manager.
few files are is very small size so they are downloaded very quickly while still we are in loop (addDownloadTask). this adding makes crash on
self.downloadingArray[index] = downloadModel
because downloaded files are removed from array
to reproduce you can use the following
for down in availableDownloadsArray { let fileURL : down as NSString let fileName : NSString = fileURL.lastPathComponent as NSString mzDownloadingViewObj?.downloadManager.addDownloadTask(fileName as String, fileURL: fileURL.addingPercentEscapes(using: String.Encoding.utf8.rawValue)!, destinationPath: myDownloadPath) }
Getting the same crash when downloading two files at line 209 MZDownloadManager.URLSession(_:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:)
There seems to be an array index out of bounds error at line 222 in MZDownloadManager.swift here:
self.downloadingArray[index] = downloadModel
It seems that when the first download completes, it is removed from the downloadingArray, but the second download's index does not change from 1 to 0. We could resolve this by changing downloadingArray to a dictionary, and changing the downloadModel's index to some randomly generated string. Thoughts?