0

In my application functionality user can download folder and file from server.

Application flow Steps

  1. Download Folder button click

  2. FolderSize = API call "Get folder info" (this API return size of folder and list of file URL which is contain by folder)

  3. DeviceFreeMemorySize = get Device free memory size

Next step for download process

if DeviceFreeMemorySize > FolderSize {
    startDownloadFile()
} else {
    display local notification
}

Everything work fine if my application running in foreground.

While on step 2 application moves in background by using home button. my API not work. and i will not get FolderSize

By using this code

let configuration = URLSessionConfiguration.background(withIdentifier: backgroundIdentifier)
let manager: SessionManager = SessionManager(configuration: configuration)
manager.download(url) // Download file 

Above code help me to download file while application in background

Bellow code for Get folder info API call

manager.request(url, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: header).responseJSON { (response:DataResponse<Any>) in

            print("Response: \(String(describing: response.result.value))")
            switch(response.result) {
            case .success(_):
                break

            case .failure(let error):
                print(error)

                break
            }
        }

But this code not work while application in background

Que:- How my API work in background.?

i have check below links:-

https://stackoverflow.com/questions/26540689/how-to-make-alamofire-download-progress-run-in-background-ios

https://medium.com/swift-programming/learn-nsurlsession-using-swift-part-2-background-download-863426842e21

AlamoFire Download in Background Session

pacification
  • 5,838
  • 4
  • 29
  • 51
jignesh Vadadoriya
  • 3,244
  • 3
  • 18
  • 29

0 Answers0