<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hardik Modha on Medium]]></title>
        <description><![CDATA[Stories by Hardik Modha on Medium]]></description>
        <link>https://medium.com/@hardik.modha?source=rss-2913c3e190a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wMHEFq4AngxZ-nXJCvvWkw.jpeg</url>
            <title>Stories by Hardik Modha on Medium</title>
            <link>https://medium.com/@hardik.modha?source=rss-2913c3e190a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 17:30:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hardik.modha/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Getting started with Download Manager in Swift]]></title>
            <link>https://medium.com/mindful-engineering/downloadmanager-3839ce4f3b55?source=rss-2913c3e190a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3839ce4f3b55</guid>
            <category><![CDATA[firedownload]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[download-manager]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[download-manager-swift]]></category>
            <dc:creator><![CDATA[Hardik Modha]]></dc:creator>
            <pubDate>Tue, 29 Jun 2021 09:08:48 GMT</pubDate>
            <atom:updated>2021-07-09T12:46:48.637Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article let me show you how easy is to download the audio or any other media file from the URL and store it into the local database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DzrOlEYfLDx-QkIp" /><figcaption>Photo by <a href="https://unsplash.com/@markuswinkler?utm_source=medium&amp;utm_medium=referral">Markus Winkler</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>For this blog, I am downloading audio files from the URL, but you can download any media file using Download Manager with minor changes in code.</p><p>So Let’s start,</p><p>In this blog, I am going to explain three main aspects of a Download manager.</p><p><strong>This article covers three main aspects:-</strong></p><ul><li>How to Download a File</li><li>How to Store a File</li><li>How to Read a File</li></ul><ol><li><strong>How to Download a File</strong></li></ol><p>First, we need to create a <strong>URLSession</strong> instance</p><p><strong>URLSession</strong></p><p>After getting the list we are going a step forward to create a URLSession object. The basic use of the URLSession object is to provide a start, pause and resume file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ae3b622b2ea5d8a2ea177b3fd54435d/href">https://medium.com/media/9ae3b622b2ea5d8a2ea177b3fd54435d/href</a></iframe><p><strong>URLSessionDownloadDelegate:-</strong></p><p>Create an instance of URLSession in your controller file and implement URLSession delegate methods in that file.</p><p><strong>didFinish</strong> delegate method will call once downloading is finish and will provide the location of the downloaded file.</p><p>We just copy that item from a downloaded location in our document directory.</p><p><strong>didWriteData</strong> delegate method will call when download is going on and it will provide the total bytes you have written and the total bytes you expect to write.</p><p>This method is used to update tasks such as to show the progress bar regarding completed download.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64b4d3b0a10fc57f976f71da668d25d1/href">https://medium.com/media/64b4d3b0a10fc57f976f71da668d25d1/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64b4d3b0a10fc57f976f71da668d25d1/href">https://medium.com/media/64b4d3b0a10fc57f976f71da668d25d1/href</a></iframe><p>Now we are going to start downloading files, for that URLSession provides a method <strong>downloadTask, </strong>that will starts to download files.</p><p><strong>Start download Task: -</strong></p><p>The below code will start downloading a file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50d3c24b5d9bfe7ed3f0f57fec5ac2ff/href">https://medium.com/media/50d3c24b5d9bfe7ed3f0f57fec5ac2ff/href</a></iframe><p><strong>URLSession also provides the facility to pause and resume download tasks.</strong></p><p><strong>Pause the task:-</strong></p><p>URLSession will provide an easy way to pause ongoing tasks. For that URLSession has method name <strong>cancel</strong> by providing resuming data.</p><p>The below code shows the functionality of pausing the ongoing task</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/834f76fc2b038d943442b84bee0fafcc/href">https://medium.com/media/834f76fc2b038d943442b84bee0fafcc/href</a></iframe><p><strong>Resume the task</strong></p><p>With pausing functionality, URLSession also provides an easy way to resume the task from where downloading has stopped.</p><p>This can be achieved by <strong>downloadTask </strong>method to resume tasks.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c6e4632212ea9e16d8cdefd381cbe30/href">https://medium.com/media/2c6e4632212ea9e16d8cdefd381cbe30/href</a></iframe><p>Here we are done with the start, pause and resume download file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*GK6G_LKVxtMAKN7fepRpcA.gif" /></figure><p><strong>Store download file in File System.</strong></p><p>Now moving forward after completing the download task, we will store that file in our file system.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2fe73f91573c6acc83c454ef15a99209/href">https://medium.com/media/2fe73f91573c6acc83c454ef15a99209/href</a></iframe><p>After storing the file in a file system, we are ready to play, pause and stop the song.</p><p><strong>AVAudioPlayer</strong></p><p>iOS has an InBuilt Framework called <strong>AVAudioPlayer</strong> which is easy to use and integrate so let’s use it and see how that helps us.</p><p>With the help of <strong>AVAudioPlayer</strong> we can easily manage to play, pause, and stop audio.</p><p>To play, pause and stop audio files using AVAudioPlayer let’s get started and go ahead to integrate it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*eA2n_IyrEkyl_R2-mHBnKA.gif" /></figure><p>First, create a reference of the audio player as shown below -</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31cd8aacf828fca54f343202461914ec/href">https://medium.com/media/31cd8aacf828fca54f343202461914ec/href</a></iframe><p>Now we going to create <strong>AVAudioPlayer</strong> and play audio</p><p>For that below code will create a player and play the audio file-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc78356a60efcbf7bfca05b74148b563/href">https://medium.com/media/cc78356a60efcbf7bfca05b74148b563/href</a></iframe><p>After that to pause ongoing audio, use the below snippet-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7bbffc92a74888aaeb6fe0e280bb6f4/href">https://medium.com/media/a7bbffc92a74888aaeb6fe0e280bb6f4/href</a></iframe><p>Lastly, to stop the audio file, the below code is used-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23f45c994970eccfe43419be00fe0727/href">https://medium.com/media/23f45c994970eccfe43419be00fe0727/href</a></iframe><p>Finally, it’s done 😎</p><p><strong>Thanks for reading!</strong></p><p><strong>Happy Coding!</strong></p><p><strong>Source Code:-</strong></p><p><a href="https://github.com/Mindinventory/DownloadManager">https://github.com/Mindinventory/DownloadManager</a></p><p><strong>Reference Link:-</strong></p><p><a href="https://jmsliu.com/3534/download-file-in-ios-start-pause-and-resume.html">Download File in iOS Start Pause and Resume</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3839ce4f3b55" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindful-engineering/downloadmanager-3839ce4f3b55">Getting started with Download Manager in Swift</a> was originally published in <a href="https://medium.com/mindful-engineering">Mindful Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>