0

Sometimes my application terminates itself with this exception when the user presses the button but the error code is not always same. Sometime it is Thread 11: signal SIGABRT sometime it is Thread 13: signal SIGABRT

What is the main problem for this error?

    @IBAction func emailchk(_ sender: Any) {
    if email.text == ""  {
        let messagebox = UIAlertController(title: "PSM Passport | Reset Password",message: "กรุณากรอก อีเมลที่คุณใช้เปิดบัญชี เพื่อทำการเปลี่ยนรหัสผ่าน",preferredStyle: UIAlertControllerStyle.alert)
        messagebox.addAction(UIAlertAction(title: "OK", style: .default ))
        present(messagebox, animated: true, completion: nil)


    } else {

        let logginbox = UIAlertController(title: "PSM Passport | Checking", message:
            "กำลังตรวจสอบบัญชีที่คุณระบุมาอยู่ กรุณารอซักครู่", preferredStyle: UIAlertControllerStyle.alert)


        self.present(logginbox, animated: true, completion: nil)


        let request = NSMutableURLRequest(url: NSURL(string: "some url that linked to the php file in my server")! as URL)
        request.httpMethod = "POST"

        var postString = "username=\(email.text!)"
        request.httpBody = postString.data(using: String.Encoding.utf8)
        let task = URLSession.shared.dataTask(with: request as URLRequest) {
            data, response, error in

            if error != nil {
                logginbox.dismiss(animated: true){
                    let alertController = UIAlertController(title: "PSM Passport | ไม่สามารถติดต่อกับ Server ได้", message:
                        "ระบบไม่สามารถทำการติดต่อกับ Server ได้ กรุณาตรวจสอบการเชื่อมต่อของคุณเเล้วลองใหม่อีกครั้ง หากปัญหานี้ยังคงเกิดขึ้นเรื่อยๆ กรุณาติดต่อ SCI-Code Team เพื่อดำเนินการเเก้ไขปัญหาต่อไป", preferredStyle: UIAlertControllerStyle.alert)
                    alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default,handler: nil))

                    self.present(alertController, animated: true, completion: nil)
                }
                return
            }



            let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
            var a = responseString as! String

            if a == "notfround\n" {
                logginbox.dismiss(animated: true) {
                    let errormsg = UIAlertController(title: "PSM Passport | Reset Password", message:
                        "ระบบไม่พบบัญชี PSM Passport นี้ในระบบ กรุณาตรวจสอบข้อมูลให้ถูกต้องเเล้วลองใหม่อีกครั้ง", preferredStyle: UIAlertControllerStyle.alert)
                    errormsg.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default,handler: nil))

                    self.present(errormsg, animated: true, completion: nil)
                }




            } else {
                var usre = self.email.text
                UserDefaults.standard.set(usre,forKey: "usernametoreset")
                UserDefaults.standard.set(a, forKey: "UIDtoreset")

                logginbox.dismiss(animated: true) {
                    let storyboard = UIStoryboard(name: "Main", bundle: nil)
                    let otpreset = storyboard.instantiateViewController(withIdentifier: "otpreset") as! UIViewController



                    self.navigationController?.pushViewController(otpreset, animated: true)


                }

                //print("\(responseString)")

            }
        }
        task.resume()


    }
}

application log

2018-01-27 18:37:20.751198+0700 PSMApplication[5108:1668568] [MC] Lazy loading NSBundle MobileCoreServices.framework
2018-01-27 18:37:20.751666+0700 PSMApplication[5108:1668568] [MC] Loaded MobileCoreServices.framework
2018-01-27 18:37:23.564509+0700 PSMApplication[5108:1668568] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2018-01-27 18:37:23.567171+0700 PSMApplication[5108:1668568] [MC] Reading from public effective user settings.
2018-01-27 18:37:41.568670+0700 PSMApplication[5108:1669041] *** Assertion failure in -[UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3698.34.4/UIApplication.m:1709
2018-01-27 18:37:41.571500+0700 PSMApplication[5108:1669041] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'accessing _cachedSystemAnimationFence requires the main thread'
*** First throw call stack:
(0x1823a3164 0x1815ec528 0x1823a3038 0x182d3d7f4 0x18bbbc758 0x18bbbc784 0x18bc19e24 0x18be52d34 0x18c22c0d8 0x18ba11a48 0x1a160f758 0x18ba2d610 0x18bcdaf9c 0x18bca92e8 0x18bca71e8 0x18bcdaa2c 0x18ba739a8 0x18ba1f0a0 0x1a15deb0c 0x18ba1ee7c 0x1a15deb0c 0x18bcd9ca0 0x18ba1ebec 0x1a15de5bc 0x100de44ec 0x100dd3eb4 0x18292dd68 0x1829466bc 0x182d79ba0 0x182cb9894 0x182ca94c4 0x101c6528c 0x101c719e4 0x101c6528c 0x101c719e4 0x101c718a4 0x182d7b878 0x101c6528c 0x101c72678 0x101c70f08 0x101c769d0 0x101c766f4 0x181fcb06c 0x181fcab6c)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 
Bonifacio2
  • 3,405
  • 6
  • 34
  • 54
Siratee K.
  • 187
  • 2
  • 12
  • Looks like running UI operation not on main thread... try to execute dismiss blocks in DispatchQueue.main.async { } – Tomasz Czyżak Jan 27 '18 at 12:10
  • Possible duplicate of [iPhone App Crash with error \[UIApplication \_cachedSystemAnimationFenceCreatingIfNecessary:\]](https://stackoverflow.com/questions/39695328/iphone-app-crash-with-error-uiapplication-cachedsystemanimationfencecreatingif) – Cœur Aug 07 '18 at 07:53

2 Answers2

1

Mainthread issues interaction between dismiss and present? Also completion block on URLSession ;)

DispatchQueue.main.async {
    logginbox.dismiss(animated: true) {
        let alertController = UIAlertController(...)
        alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default,handler: nil))

         DispatchQueue.main.async {
            self.present(alertController, animated: true, completion: nil)
         }
    }
}

Please handle weakself by your self ;)

Tomasz Czyżak
  • 1,118
  • 12
  • 13
0

Try a DispatchQueue.main.async at all view operations like present or navigationController.pushViewController

For example

DispatchQueue.main.async {
  self.present(messagebox, animated: true, completion: nil)
}

Run the debug mode and have a look at which line the code is throwing the exception (and post it).

kuzdu
  • 7,124
  • 1
  • 51
  • 69