let task = URLSession.shared.dataTask(with: request, completionHandler: {data, response, error in
if (error == nil) {
do{
let json = try JSONSerialization.jsonObject(with: data!) as! [String: AnyObject]
print(json["spToken"])
if TokenStore.setSpToken(token: json["spToken"] as! String){
//ここで画面遷移しようとする
self.navigationController?.popViewController(animated: true)
}else{
print("login error")
}
}catch{
print(error.localizedDescription)
}
print("ok")
} else {
print(error)
}
})
task.resume()
URLSession.shared.dataTaskの中で画面遷移しようとしたら、めちゃくちゃ時間がかかり
こんなログが出てきました
This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.
どうやら、メインスレッドではないところで呼び出してしまったのが原因のようです
DispatchQueue.main.async {
self.navigationController?.popViewController(animated: true)
}
これで解決