This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes

前端 未结 6 1738
醉话见心
醉话见心 2020-11-30 06:00

I get this log in the console when I am running my application in is simulator. Haven\'t seen this in iOS 8. I am not quite sure whats causing this. Has anyone else come acr

6条回答
  •  旧巷少年郎
    2020-11-30 06:23

    All UI part updation you need to move into MAIN thread of App.

    I was calling a createMenuView() into background and i got below error

    "This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes"

    So I called above method into Main thread Using

        DispatchQueue.main.async {
        }
    

    in SWIFT 3.0 and Xcode 8.0

    Correct code written below :

    RequestAPI.post(postString: postString, url: "https://www.someurl.com") { (succeeded: Bool, msg: String, responceData:AnyObject) -> () in
    
            if(succeeded) {
                print(items: "User logged in. Registration is done.")
    
                // Move to the UI thread
                DispatchQueue.main.async (execute: { () -> Void in
    
                    //Set User's logged in
                    Util.set_IsUserLoggedIn(state: true)
                    Util.set_UserData(userData: responceData)
                    self.appDelegate.createMenuView()
    
                })
    
            }
            else {
                // Move to the UI thread
                DispatchQueue.main.async (execute: { () -> Void in
                    let alertcontroller = UIAlertController(title: JJS_MESSAGE, message: msg, preferredStyle: UIAlertControllerStyle.alert)
                    alertcontroller.title = "No Internet"
                    alertcontroller.message = FAILURE_MESSAGE
                    self.present(alertcontroller, animated: true, completion: nil)
                })
            }
        }
    

提交回复
热议问题