How to execute alamofire background upload request? How to execute alamofire background upload request? xcode xcode

How to execute alamofire background upload request?


from Background Transfer Considerations :

Only upload tasks from a file are supported (uploading from data objects or a stream will fail after the program exits).

that means it is limitation from NSURLSession - you need you upload from a file and then try to solve the other error with file

Update

appDeligate.log.debug("request was sended")let tempZipFilePath = UtilDirectory.tempZipPath.tweak()alamoFireManager.upload(tempZipFilePath,                        to: deligate.url,                        method: .post,                        headers: headers)


did you see this section Open Radars:

Open Radars

The following radars have some effect on the current implementation of Alamofire.

rdar://26870455 - Background URL Session Configurations do not work in the simulator


Use below code once, Its working for me

import Alamofire

var sessionManager: Alamofire.SessionManagervar backgroundSessionManager: Alamofire.SessionManager self.sessionManager = Alamofire.SessionManager(configuration: URLSessionConfiguration.default)self.backgroundSessionManager = Alamofire.SessionManager(configuration: URLSessionConfiguration.background(withIdentifier: "com.youApp.identifier.backgroundtransfer"))backgroundSessionManager.upload(multipartFormData: blockFormData!, usingThreshold: UInt64.init(), to: url, method: .post, headers: APIManager.headers(), encodingCompletion: { encodingResult inswitch encodingResult {case .success(let upload, _, _):    upload.uploadProgress {        (progress) in        let p = progress.fractionCompleted * 100        uploadProgress(p)    }    upload.responseJSON { response in        switch(response.result) {        case .success(let JSON):            DispatchQueue.main.async {                    print(JSON)            }        case .failure(let error):            DispatchQueue.main.async {                print(error)            }        }    }case .failure(let error):    DispatchQueue.main.async {        print(error)    }}})