我需要将zip文件发送到服务器端。
有我的要求,我需要在后台工作
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 10 // seconds
alamoFireManager = Alamofire.SessionManager(configuration: configuration)
appDeligate.log.debug("request was sended")
alamoFireManager.upload(deligate.data!,
to: deligate.url,
method: .post,
headers: headers)
.uploadProgress(closure: {
progress in
print("Upload Progress: \(progress.fractionCompleted)")
})
.validate()
.responseJSON {}
Run Code Online (Sandbox Code Playgroud)
现在它可以正常工作,但是我需要在后台执行此操作。根据Alamofire自述文件
https://github.com/Alamofire/Alamofire
它说
使用后台配置创建会话管理器
让配置= URLSessionConfiguration.background(withIdentifier:“ com.example.app.background”)
让sessionManager = Alamofire.SessionManager(configuration:配置)
我更改了配置以对应后台配置
现在看起来像这样
let configuration = URLSessionConfiguration.background(withIdentifier: "com.room.myApp")
configuration.timeoutIntervalForRequest = 10 // seconds
alamoFireManager = Alamofire.SessionManager(configuration: configuration)
alamoFireManager.upload(deligate.data!,
to: deligate.url,
method: .post,
headers: headers)
.uploadProgress(closure: {
progress in
print("Upload Progress: \(progress.fractionCompleted)")
})
.validate()
.responseJSON {} …Run Code Online (Sandbox Code Playgroud)