LoginSignup
3
1

More than 5 years have passed since last update.

URLSession.shared.dataTaskで画面遷移しようとしたら、エラーが出た

Posted at
 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)

                        }

これで解決

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1