In a modern iPhone app, a smooth user experience is quite important. To achieve this, caching the internet resources to local is a good approach. Therefore, to make the app more smoothly when users open it, downloading images and videos and saving them locally will quite improve the app starting speed. In the last tutorial, I have demonstrated how to download files by Swift 5 and watch the download status such as progress. The downloading task is controlled by 3 buttons: a start button to start, a pause button to pause and resume, a stop button to stop. In this tutorial, I will show how to save the downloaded file in local and open it by default in the iPhone. The whole tutorial is developed under the latest Swift.Read more
Download File in Swift5 Start Pause and Resume
Several years ago, I post an article to demostrate how to implement download file features in iOS. In that article, I am using swift 2 to write all features including start, pause, resume and show progress. Lots of readers ask me to improve a new version with swift4 or swift5. As the language changes a lot, some of the APIs has been deprecated. That’s the reason why I write this artiel. In this article, I will use the latest version of Swift (current version is 5) to show you how to implement download file features.Read more
Download Multiple Files Simultaneously in iOS
Downloading multiple files concurrently is a necessary feature for a download manager app. Using UITableView is the best solution to manage multiple downloading tasks at the same time. In a table, we can maintain each separate downloading task in each table row. In this tutorial, I will use UITableView to manage all download threads. In each UITableView cells, I will put a progress bar inside to observe the downloading progress. To control the download task separately, I will also put a start button and pause button in each UITableView cell. Therefore, I will also show you how to custom UITableView cells in this tutorial.
This is the tutorial 3 of iOS download manager app tutorial. In this tutorial, I will give some example to show you how to download multiple files concurrently, and use UITableView to manage each downloading task separately. You can also access the whole tutorial series with following links:
iOS CollectionView Brief Tutorial
UICollectionView is widely used in iOS apps. The most common example is the iOS photo app, which has a stylish way to display all photos in grid view or stack view. The collection view provide a simple way to let us build complicated layout by customising its cell view. Different from table view, collection view will show its cell views in grid layout. Each cell view can have different width and height. Therefore, it gives us more room to make special layout by UICollectionView.
Recently, I am going to create a file manager which will look very similar with iBooks, but will show cover and title altogether with different size. In the future, we can simply use this component in many apps, such as mp3 album app, file download manager app, or comic books app.
Start a Simple App with Collection View
Similar with UITableView and UITableViewCell, the collection view is also made up of UICollectionView and UICollectionViewCell. Additional, we can also customize the layout by setting collectionViewLayout. To build up a grid style view with UICollectionView, we can implement following delegates:
- UICollectionViewDelegate: the delegate set up the collection view.
- UICollectionViewDataSource: the delegate provide the data source for collection view.
- UICollectionViewDelegateFlowLayout (optional): UICollectionView provide us a flow layout. When we use the default layout, we can use this delegate to configure the layout such as size of items and the spacing between items. We can also set collectionViewLayout as our customized layout.
Save and Load Downloaded File Locally
My Download Manager app is a real project which will manage download tasks. It allow users to start download a file, pause or resume the download task, and stop a download task. In tutorial 1, I already show you all the basic functions, such as starting a download, pause, resume and stop it. However, these basic functions are really not enough. For example, if I pause the download task and quit the app, the app will lose all downloaded data.
The only solution for that is saving the downloaded data into iOS device locally when we pause the download data. So we will not lose the data even we quit the app. If we want to resume the download task, we can load the data from where we store it locally and continue to download the rest of it.