The use of invalidateAndCancel() comes up with another problem which is to reinitialize the session again if u need to use it again. After searching on this problem i got the answer of Cnoon's Alamofire Background Service, Global Manager? Global Authorisation Header?. Tried creating the manager but when it is called it never re-initialize the value, to anticipate this problem i did a small cheat i tried giving my session new name each time.
func reset() -> Manager {
let configuration: NSURLSessionConfiguration = {
let identifier = "com.footbits.theartgallery2.background-session\(sessionCount)"
let configuration = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier(identifier)
return configuration
}()
return Alamofire.Manager(configuration: configuration)
}
func cancelAllRequests() {
manager.session.invalidateAndCancel()
sessionCount += 1
manager = reset()
}
Now i am curious of what is happening in background like the previous session is still there or has been removed by alamofire because if it is still there how many session can i create and what will be the after affect? because i tried:
manager.session.resetWithCompletionHandler {
print("Session reset")
}
it doesnt work.