iOS应用程序因未捕获的异常而终止,且没有堆栈跟踪 (使用Swift)

5

我正在编写关于在我的应用中为UI元素添加动画效果的代码。在修改某些UI元素的透明度时,出现了如下错误:

libc++abi.dylib: terminating with uncaught exception of type NSException

没有堆栈跟踪或指示错误可能在哪里,只有一个指向AppDelegate类的Signal SIGABRT。

该应用程序在先前的版本上工作,并且在那之后我更改的是alpha设置,之后我撤消了更改以尝试调试情况。我已尝试禁用某些我最近修改的代码部分(如Game Center),并尝试设置断点,但无法使应用程序正常工作。

我的问题 - 这是什么错误,它从何而来?

如果您需要查看,请参阅此处最近修改的一些代码:

//This code is called in a Game Center Authentication method
         UIView.animate(withDuration: 0.5, animations: {
                        self.pointsIndicator.center.x += self.view.bounds.width
                       // self.pointsIndicator.alpha = 1
                    })
                    UIView.animate(withDuration: 0.5, delay: 0.3, options: [], animations: {
                        self.pointsLabel.center.x += self.view.bounds.width
                       // self.pointsLabel.alpha = 1
                        }, completion: nil)

视图将要出现:

override func viewWillAppear(_ animated: Bool) {

    //Setup animations
    print("\(progBar.center.x) Before")
    pointsIndicator.center.x  -= view.bounds.width
    pointsLabel.center.x -= view.bounds.width
    progBar.center.x -= view.bounds.width
    masterLabel.center.x -= view.bounds.width

    pointsIndicator.alpha = 0
    pointsLabel.alpha = 0
    progBar.alpha = 0
    masterLabel.alpha = 0

}

更新: 我在调试器上运行了bt命令。这是输出结果:

* thread #1: tid = 0x6646da, 0x0000000110607e6e libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x0000000110607e6e libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x000000011063e8fb libsystem_pthread.dylib`pthread_kill + 90
frame #2: 0x00000001103570b3 libsystem_c.dylib`abort + 129
frame #3: 0x000000010fe6243a libc++abi.dylib`abort_message + 266
frame #4: 0x000000010fe86a9f libc++abi.dylib`default_terminate_handler() + 267
frame #5: 0x000000010985359f libobjc.A.dylib`_objc_terminate() + 103
frame #6: 0x000000010fe83c09 libc++abi.dylib`std::__terminate(void (*)()) + 8
frame #7: 0x000000010fe83894 libc++abi.dylib`__cxa_rethrow + 99
frame #8: 0x00000001098534b7 libobjc.A.dylib`objc_exception_rethrow +  40
frame #9: 0x0000000106c07bf1 CoreFoundation`CFRunLoopRunSpecific + 433
frame #10: 0x0000000107d4ac00 UIKit`-[UIApplication _run] + 459
frame #11: 0x0000000107d50e8b UIKit`UIApplicationMain + 159
* frame #12: 0x000000010681423f MathsRobot LearnMaths`main + 111 at     AppDelegate.swift:19
frame #13: 0x00000001102ab6bd libdyld.dylib`start + 1
frame #14: 0x00000001102ab6bd libdyld.dylib`start + 1

更新:AppDelegate:19

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

在你的应用程序崩溃后,在控制台中输入“bt”并查看。 - Brjv
AppDelegate.swift:19 是类的定义。 - themathsrobot
请发布您的AppDelegate.swift文件中第19行的代码片段。 - Brjv
https://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1 - dan
AppDelegate:19 已更新 - themathsrobot
1
尝试设置一个“所有异常”断点 - 有时这会让您更接近崩溃实际位置的堆栈跟踪。 - Rich Tolley
1个回答

15

感谢jeromeshr在Apple论坛上的贡献。我在从Swift代码调用Cocoapod中的一些Objective-C代码时遇到了这个问题。如果您将OS_ACTIVITY_MODE标志设置为环境变量,则会阻止正确的堆栈跟踪显示。它在我所有的应用程序中都被设置为避免控制台中无用信息的无休止流。只需在调试期间取消选中旁边的框(不需要删除它)即可解决问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接