Error Code=-1005 "The network connection was lost." in Swift while consuming Web Service
<p>I'm working on a iOS project in Swift 2.0, which has Web service calls, these services are slow to respond and that is normal, can be up to 1 minute or a little more, when i call the service 70% of the time it answers with the error "the network connection was lost." The tests were conducted in both simulator and different phone devices and iPad and the result is the same. The network connection is strong and the same application was also created on Android and working properly almost 100% of the time.</p>

<p>The way I call services from any view is as follows:</p>

<pre><code>@IBAction func contratarAct(sender: AnyObject) {
    conexion.delegate = self
    loadingView = MEXLoadingView(delegate: self, title: "Espere por favor", percent: false, view: self.view)
    self.loadingView.showAnimated(true)
    let url = urlServicios.urlBaseServicios + "/" + idSolicitud + "/" + idNoCliente + "/CONTRATO"
    conexion.consultaServicioGET(url, httpMethod: "PUT")
}
</code></pre>

<p>And the method that is executed is as follows:</p>

<pre><code>func consultaServicioGET(url : String, httpMethod : String ){
    let urlString = url
    let request = NSMutableURLRequest(URL: NSURL(string: urlString)!)
    request.timeoutInterval = 540
    request.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData
    request.addValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")

    var session = NSURLSession.sharedSession()
    request.HTTPMethod = httpMethod

    let urlconfig = NSURLSessionConfiguration.defaultSessionConfiguration()
    urlconfig.timeoutIntervalForRequest = 540
    urlconfig.timeoutIntervalForResource = 540
    session = NSURLSession(configuration: urlconfig, delegate: self, delegateQueue: nil)

    let task = session.dataTaskWithRequest(request , completionHandler: {
        (data:NSData?, response:NSURLResponse?, error:NSError?) in

        if error != nil {
            let jsonError : NSDictionary = NSDictionary()
            self.delegate?.respuestaServicioGET!(jsonError, mensaje: "\(error!.localizedDescription)")
            return
        }

        let jsonString = NSString(data: data!,encoding: NSASCIIStringEncoding)
        let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)

        let json: NSDictionary = try! NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary

        if (json.isKindOfClass(NSDictionary) ){
            self.delegate?.respuestaServicioGET!(json, mensaje: "OK")
        }else{
            let jsonError : NSDictionary = NSDictionary()
            self.delegate?.respuestaServicioGET!(jsonError, mensaje: "ERROR")
        }
    })
    task.resume()
}
</code></pre>

<p>the error displayed is:</p>

<p>error=Optional(Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={NSUnderlyingError=0x7fbde5f51df0 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={_kCFStreamErrorCodeKey=-4, _kCFStreamErrorDomainKey=4}}, NSErrorFailingURLStringKey=<a href="https://particulares-gw-obparticularesmx-pre.appls.cto2.paas.gsnetcloud.com:443/OPB/57dadf7de4b0ac2e518de44a/57dadf7de4b06c6b04ef0dcf/CONTRATO" rel="nofollow">https://particulares-gw-obparticularesmx-pre.appls.cto2.paas.gsnetcloud.com:443/OPB/57dadf7de4b0ac2e518de44a/57dadf7de4b06c6b04ef0dcf/CONTRATO</a>, NSErrorFailingURLKey=<a href="https://particulares-gw-obparticularesmx-pre.appls.cto2.paas.gsnetcloud.com:443/OPB/57dadf7de4b0ac2e518de44a/57dadf7de4b06c6b04ef0dcf/CONTRATO" rel="nofollow">https://particulares-gw-obparticularesmx-pre.appls.cto2.paas.gsnetcloud.com:443/OPB/57dadf7de4b0ac2e518de44a/57dadf7de4b06c6b04ef0dcf/CONTRATO</a>, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-4, NSLocalizedDescription=The network connection was lost.})</p>

<p>I add some code like the following:</p>

<p>urlconfig.timeoutIntervalForRequest = 540
 urlconfig.timeoutIntervalForResource = 540</p>

<p>Trying to get more "timeout" but this is not looks like a timeout. </p>

<p>I can not get out of this error for days, any help will be greatly appreciated. I'm desperate.</p>