0

I am using a NSURLSessionDataTask to get JSON data from a device that opens an adhoc-WiFi which is joined by an iPhone. (The connection is running via TCP).

The device is pretty slow - it takes roundabout 5sec to send the particular response. After firing the request via dataTask.resume() my app is just waiting for the completionHandler to be called. Unfortunately the request is fired again and again (each after a delay of ~ 1 sec). I guess this is initiated by the dataTask or NSURLSession. I can monitor the repeated requests when debugging the device.

Here's the code I'm using:

let URL = NSURL(string: "<myURL>")! 

let configuration = NSURLSessionConfiguration.ephemeralSessionConfiguration()
configuration.HTTPShouldUsePipelining = false
configuration.HTTPMaximumConnectionsPerHost = 1
configuration.allowsCellularAccess = false
configuration.timeoutIntervalForRequest = 30

let session = NSURLSession(configuration: configuration)
let dataTask = session.dataTaskWithURL(URL) {
// the request gets fired repeatedly before this completionHandler is called!
(data, response, error) -> Void in
...
}

dataTask.resume()

Does anyone know how to prevent iOS from re-firing these requests?

benrudhart
  • 1,406
  • 2
  • 13
  • 25
  • You'l have greater chances of getting answers if you paste your code here. – Xcoder Apr 17 '15 at 07:22
  • Are you using https? If so Implement the func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential!) -> Void) – Xcoder Apr 17 '15 at 07:38
  • No, I'm not using https - the device doesn't support that. I'm just accessing via http. – benrudhart Apr 17 '15 at 07:54

0 Answers0