6

Problem

I recently updated my iPhone to iOS 10.3.1 and Xcode to Version 8.3.2. Currently, I have an app which runs a few URLRequests once my app launches.

However, after updating both iOS and Xcode, the app occasionally return an error message:

error in connection_block_invoke_2: Connection interrupted

The message is quite vague but I assumed it has something to do with the URLRequests since it mentions "Connection interrupted".

Whenever this error message appears, it will "freeze" the app for ~5s before getting the data from the server.


Question

So, what does this error message actually mean? And how can I minimise it or fix it?


Example of one URLRequest:

func checkLogin () {
    let username = txtUsername.text!
    let password = txtPassword.text!

    let post = "username=\(username)&password=\(password)"
    NSLog("PostData: %@",post);
    let url:URL = URL(string:"https://example.com/login.php")!
    let postData = post.data(using: .utf8)!
    let postLength = String( postData.count )
    var request = URLRequest(url: url)

    request.httpMethod = "POST"
    request.httpBody = postData
    request.setValue(postLength as String, forHTTPHeaderField: "Content-Length")
    request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
    request.setValue("application/json", forHTTPHeaderField: "Accept")
    let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
        if error != nil {
            return
        }
        if let jsonData = (try? JSONSerialization.jsonObject(with: data!, options: [])) as? [String:Any] {
            let success = jsonData["success"] as! Int
            if success == 1 {
                //do something,
            }
            else {
                //show alert
            }
        }

    })
    task.resume()
}

Duplicates

The following questions does not solve my problem as:

Community
  • 1
  • 1
Panda
  • 6,955
  • 6
  • 40
  • 55

0 Answers0