WaitUntilAllTasksAreFinished 오류 Swift
[ Submit ]버튼을 눌렀을 때 loginViewController에서 다음 콜이 발생합니다.
let http = HTTPHelper()
http.post("http://someUrl.com/Login/userEmail/\(username.text)/Pswd/\(userPass.text)", postCompleted: self.checkLogin)
전송한 checkLogin 함수는 다음 작업만 수행합니다.
func checkLogin(succeed: Bool, msg: String){
if (succeed){
self.performSegueWithIdentifier("logInTrue", sender: self)
}
}
포스트 함수는 HTTPHelper 클래스는 다음과 같습니다.
func post(url : String, postCompleted : (succeeded: Bool, msg: String) -> ()) {
var request = NSMutableURLRequest(URL: NSURL(string: url)!)
var session = NSURLSession.sharedSession()
request.HTTPMethod = "POST"
var err: NSError?
self.task = session.dataTaskWithURL(NSURL(string: url)!) {(data, response, error) in
var strData = NSString(data: data, encoding: NSUTF8StringEncoding)
var err: NSError?
var json = NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments, error: &err) as? NSDictionary
var msg = "No message"
// Did the JSONObjectWithData constructor return an error? If so, log the error to the console
if(err != nil) {
let jsonStr = NSString(data: data, encoding: NSUTF8StringEncoding)
postCompleted(succeeded: false, msg: "Error")
}
else {
// The JSONObjectWithData constructor didn't return an error. But, we should still
// check and make sure that json has a value using optional binding.
if let parseJSON = json {
// Okay, the parsedJSON is here, let's get the value for 'success' out of it
if let success = parseJSON["result"] as? Bool {
postCompleted(succeeded: success, msg: "Logged in.")
}
return
}
else {
// Woa, okay the json object was nil, something went worng. Maybe the server isn't running?
let jsonStr = NSString(data: data, encoding: NSUTF8StringEncoding)
postCompleted(succeeded: false, msg: "Error")
}
}
}
self.task!.resume()
}
checkLogin 함수가 정상적으로 호출된 경우: true는 SegueWithIdentified 함수를 수행하지 못합니다.에러는 다음과 같습니다.
[UIKeyboard TaskQueue waitTilAllTaskSareFinished], /SourceCache/UIKit_Sim/UIKit-3318.16.14/키보드/에서 어설션 오류가 발생했습니다.UIKeyboardTaskQueue.m:374 2014-11-15 17:41:29.540 Wavess [8462:846477] *** 예외 'NSInternalInconsistencyException'으로 인해 앱을 종료하고 있습니다.이유: '-[UIKeyboard Taskueueueueueueueueue to MayAll Finfinished Affics]
해결책을 찾기가 어렵지만 url 태스크가 다른 스레드에서 실행되고 있는 동안에는 뷰 컨트롤러 사이를 통과할 수 없을 것 같습니다.여러분, 잘 부탁드립니다!
당신의.checkLogin
다른 스레드에서 함수가 호출되고 있으므로 호출하기 전에 메인 스레드로 다시 전환해야 합니다.self.performSegueWithIdentifier
사용하는 것을 선호합니다.NSOperationQueue
:
func checkLogin(succeed: Bool, msg: String) {
if (succeed) {
NSOperationQueue.mainQueue().addOperationWithBlock {
self.performSegueWithIdentifier("logInTrue", sender: self)
}
}
}
대체: xCode 10.1 1/2019
func checkLogin(succeed: Bool, msg: String) {
if (succeed) {
OperationQueue.main.addOperation {
self.performSegue(withIdentifier: "logInTrue", sender: self)
}
}
}
Xcode 8.0 및 Swift 3에서는 다음과 같은 구조로 변경되었습니다.
OperationQueue.main.addOperation{
<your segue or function call>
}
저도 같은 문제를 안고 있었는데, 위의 답변을 참고하여 해결했습니다.감사합니다 @Nate
var storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var vc: UINavigationController = storyBoard.instantiateViewControllerWithIdentifier("AppViewController") as! UINavigationController
NSOperationQueue.mainQueue().addOperationWithBlock {
self.presentViewController(vc, animated: true, completion: nil)
}
비동기 태스크 내부에서 텍스트 상자의 내용을 변경하려고 할 때 이 문제가 발생했습니다.
이 솔루션에서는 Dispatch Queue(Xcode 8.0 및 Swift 3.0)를 사용하고 있었습니다.
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.textBox.text = "Some Value"
}
언급URL : https://stackoverflow.com/questions/26947608/waituntilalltasksarefinished-error-swift
'programing' 카테고리의 다른 글
iPhone은 사용할 수 없습니다.장치를 다시 연결하십시오. (0) | 2023.04.09 |
---|---|
스키마에 있는 모든 테이블의 개수를 가져옵니다. (0) | 2023.04.04 |
wp-rest api 응용 프로그램에서 wordpress nonce를 사용할 수 없습니다. (0) | 2023.04.04 |
Web API Put Request가 Http 405 Method Not Allowed 오류를 생성합니다. (0) | 2023.04.04 |
치명적인 오류:허용된 메모리 크기 268435456바이트가 모두 사용됨(71바이트 할당 시도) (0) | 2023.04.04 |