In my application functionality user can download folder and file from server.
Application flow Steps
Download Folder button click
FolderSize = API call "Get folder info" (this API return size of folder and list of file URL which is contain by folder)
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:-