快速错误线程(一些数字):信号SIGABRT



有时,当用户按下按钮但错误代码并不总是相同时,我的应用程序会因此异常而终止自身。有时是Thread 11: signal SIGABRT有时是Thread 13: signal SIGABRT

此错误的主要问题是什么?

    @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 == "notfroundn" {
                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()

    }
}

应用程序日志

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) 

主线程问题 解除和呈现之间的交互?也是 URL 上的完成块;)

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)
         }
    }
}

请用自己的;)来处理弱自己

尝试

在所有视图操作(如presentnavigationController.pushViewController(中使用DispatchQueue.main.async

例如

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

运行调试模式并查看代码引发异常的哪一行(并发布它(。

最新更新