ios - Alamofire: How to download files sequentially -


i have array of video files want download. using loop download each of them. when loop runs, files download in parallel, causes app hang, ui freeze, cpu use go through roof.

for url in urlarray{   downloadfile(url) } 

i have function downloads file given url.

func downloadfile(s3url:string)->void{      alamofire.download(.get, s3url, destination: destination)          .progress { bytesread, totalbytesread, totalbytesexpectedtoread in              println(totalbytesread)          }          .response { request, response, _, error in              println(response)          } } 

how can change files dont download @ sametime? also, how can check download finished can update ui?

what call out function when file completes downloading (i.e. totalbytesread >= totalbytesexpectedtoread). in function, pop next item off list , call download function again new url. make array of urls , when need new item, remove array , pass download function. check if array empty , if is, know done downloading everything.

the reason can't use loop have alamofire requests asynchronous after request made, control returns , program continues before data downloaded.


Comments

Popular posts from this blog

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -