When the app goes into the background, it wants to make a single request, unfortunately it receives the error:
sessionTaskFailed (error: Error Domain = NSURLErrorDomain Code = -1005 "The network connection was lost...")
Code:
override func viewDidLoad() {
super.viewDidLoad()
notificationCenter.addObserver(self, selector: #selector(appMovedToBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
}
@objc func appMovedToBackground() {
let URL: String = "http://www.test.com/"
AF.request(URL, method: .post, parameters: parameters, headers: headers)
.responseJSON { [] response in
switch response.result {
case .success(let data):
print(data)
case .failure(let error):
print(error)
}
}
}