Alamofire to download/upload multiple files in background
<p>My app needs to have a <strong>Sync</strong> feature. i.e A similar feature like <strong>google photos</strong>. User adds some images, tags , audio &amp; bunch of other files.</p>

<p>Click on sync button &amp; the files will be uploaded/ downloaded.</p>

<p>In android I used a service that helped achieving this functionality.</p>

<p>How can I achieve this functionality using <strong>Alamofire networking library</strong>.</p>

<p>This is what I tried.</p>

<pre><code>class BackgroundDownload{
let manager = Alamofire.Manager(configuration: NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier("com.blabla.download.123"))

init(){
    for _ in 1...10{
        manager.request(NSURLRequest(URL: NSURL(string: "https://static.pexels.com/photos/479/landscape-nature-sunset-trees.jpg")!)).response { (request, response, data, let error) in
            print(response)
            print(error)

        }
    }
}
</code></pre>

<p>}</p>

<p>It is a sample code. I call this from a ViewController.
The problems I am facing.</p>

<p>1.Where should I call my file downloading code so that <strong>it continues to run in background</strong>.</p>

<ol start="2">
<li>How to resume downloading if user shuts the app or for some reason the app restarts.</li>
</ol>