UIKeyboardTaskQueue may only be called from the main thread
You should call your UIAlertController on the main thread because you're dealing with the ui.
Swift 2.X
dispatch_async(dispatch_get_main_queue(),{ var alert = UIAlertController(title: "Chargement", message: "Envoi des informations...", preferredStyle: UIAlertControllerStyle.Alert) viewController.presentViewController(alert, animated: true, completion: nil) answer = NSString(data: data!, encoding: NSUTF8StringEncoding)! print(answer) var complete = false alert.dismissViewControllerAnimated(true, completion: { () -> Void in complete = true }) while(!complete) { }}
Swift 4.2
DispatchQueue.main.async { var alert = UIAlertController(title: "Chargement", message: "Envoi des informations...", preferredStyle: UIAlertControllerStyle.Alert) viewController.presentViewController(alert, animated: true, completion: nil) let answer = String(data: data!, encoding: .utf8)! print(answer) var complete = false alert.dismissViewControllerAnimated(true, completion: { () -> Void in complete = true }) while(!complete) { }}