V
V
Vladislav Pavlenko2019-01-29 19:44:46
iOS
Vladislav Pavlenko, 2019-01-29 19:44:46

Why is file upload progress not showing after exiting the background state?

I'm uploading a file. I use Alamofire. Set up SessionManager to be able to load in the background.

let downloadSession: SessionManager = {
        return Alamofire.SessionManager(
            configuration: URLSessionConfiguration.background(
                withIdentifier: (Bundle.main.bundleIdentifier ?? "") + ".background"
            )
        )
    }()

After clicking the "download" button, everything works well, the progress is displayed. After hiding and opening the application after a short time, no more data is returned in the progress block.
@discardableResult
    static func download(path: String,
                         parameters: [String: Any]?,
                         progressBlock: ProgressBlock?,
                         successBlock: SuccessBlock?,
                         errorHandlerBlock: ErrorHandlerBlock?) -> DownloadRequest {
        
        return downloadSession.download(URL(string: APIMethod.shortURL + path)!,
                                        method: .get,
                                        parameters: parameters,
                                        encoding: JSONEncoding.default,
                                        headers: defaultMultipartHeaders,
                                        to: FileBrowser.downloadDestination).downloadProgress(closure: { (progress) in
                                            progressBlock?(progress)
                                        }).responseJSON(completionHandler: { (response) in
                                            successBlock?(response.destinationURL)
                                        })
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one pavel, 2019-01-30
@onepavel

Your question may be related to Background Modes in iOS?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question