1

I wrote

class Property{
    ...
    static var alamofireManager: SessionManager{
        let sessionConfiguration = URLSessionConfiguration.default
        sessionConfiguration.timeoutIntervalForRequest = 10
        return Alamofire.SessionManager(configuration: sessionConfiguration)
    }
    ...
}

for multiple classes' functions to use it.

However, when I use it:

Property.alamofireManager.request(loginURL).validate(contentType: ["application/json"]).responseJSON{ response in
....

I get error saying :

Task <1F6C95AA-C878-439F-87ED-1055D19E3ADD>.<1> finished with error - code: -999

I know it works if I just use Alamofire. Does anyone know why this is not working?

Thank you!

Bentaye
  • 9,403
  • 5
  • 32
  • 45
Bubu
  • 651
  • 8
  • 25
  • My guess is because you're not creating any headers unlike Alamofire's default SessionManager. Therefore important information is missing such as `Accept-Encoding` and `Accept-Language`. – Au Ris Oct 12 '17 at 21:01
  • 1
    You're also missing parentheses `()` after the var closure. Explanation here: https://stackoverflow.com/a/33115013/1433612 – Au Ris Oct 12 '17 at 21:27
  • Hmm I see. Let me try later and update. Thank you by the way! – Bubu Oct 12 '17 at 21:30
  • try this https://stackoverflow.com/a/52868844/5032981 – Prashant Gaikwad Oct 18 '18 at 07:21

1 Answers1

4

Here's what it should look like:

static let alamofireManager: SessionManager = {
    let sessionConfiguration = URLSessionConfiguration.default
    sessionConfiguration.timeoutIntervalForRequest = 10
    return Alamofire.SessionManager(configuration: sessionConfiguration)
}()
Au Ris
  • 4,541
  • 2
  • 26
  • 53