What does "error in connection_block_invoke_2: connection interrupted" mean?
Problem
I recently updated my iPhone to iOS 10.3.1 and Xcode to 8.3.2. I currently have an application that launches several URLRequest
after my application starts.
However, after updating iOS and Xcode, the app sometimes returns an error:
Error in connection_block_invoke_2: Connection interrupted
The message is rather vague, but I assumed it had something to do URLRequest
with since it mentions "Connection being dropped".
Whenever this error message appears, it will "freeze" the application ~ 5 seconds before receiving data from the server.
Question
So what does this error message mean? And how can I minimize 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 do not solve my problem:
-
What is "error in __connection_block_invoke_2: connection is interrupted" in iOS?
- I didn't get a memory save warning, so the answer doesn't apply.
-
iOS: error in __connection_block_invoke_2: connection is interrupted
- In my application, I have not used
AVCaptureMovieFileOutput
and at allAVCaptureVideoDataOutput
, so the answer does not apply either.
- In my application, I have not used
-
error in __connection_block_invoke_2: connection broken on iPad and Xcode 7 error message "in __connection_block_invoke_2: connection broken" when app is running on iPad
- No answer at all.
source to share
No one has answered this question yet
See similar questions:
or similar: