简体   繁体   中英

swift How to view progress of downloadTask in several ViewControllers

I have two viewControllers VCList(CollectionView with items) VCDetails by selecting item from VCList it opens VCDetails, on VCDetails I have button download that starts downloading huge file according selected item with showing its progress, by dismissing VCDetails I want to show progress on VCDetails, and on entering again on that VCDetails if its is still downloading I want to show continued progress of downloading. Please any suggestions on how to achieve this? Thanks a lot

This sounds like a loosely coupled notification. I would suggest having your download process broadcast Notification messages to the main thread at modest intervals (every few seconds). Then have the current view controller subscribe to those notifications and use them to update a download progress indicator.

Better yet, create a reusable download progress indicator that takes a download ID and listens for progress updates. Have your download manager return a unique download ID, and pass that to the view controllers that need to display progress. Have the view controllers install the download ID into their reusable download indicators views.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM