确定崩溃是否是Swift Runtime错误
Swift使用内存安全技术来及早发现编程错误。如果Swift运行时遇到编程错误,则运行时会捕获该错误并有意使应用程序崩溃。这些崩溃在崩溃报告中具有可识别的模式。崩溃报告中的异常信息如下所示:
Exception Type: EXC_BREAKPOINT (SIGTRAP)
...
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
寻找语言异常的迹象
Apple的系统框架在运行时遇到某些类型的编程错误时(例如,索引超出范围的数组)会抛出语言异常。要确定崩溃是否是由于语言异常引起的,请首先确认崩溃报告包含以下模式:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
由于语言异常而导致Last Exception Backtrace的崩溃在崩溃报告中也有:
Last Exception Backtrace:
0 CoreFoundation 0x19aae2a48 __exceptionPreprocess + 220
1 libobjc.A.dylib 0x19a809fa4 objc_exception_throw + 55
检查看门狗信息
系统使用看门狗来监视应用程序的响应性。如果某个应用程序无响应,则看门狗会终止该应用程序,并使用0x8badf00d“终止原因”中的代码创建一个崩溃报告:
Exception Type: EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: Namespace SPRINGBOARD, Code 0x8badf00d
在无响应的应用程序的崩溃报告中,Termination Description包含来自看门狗的有关应用程序如何花费时间的信息。例如:
Termination Description: SPRINGBOARD,
scene-create watchdog transgression: application<com.example.MyCoolApp>:667
exhausted real (wall clock) time allowance of 19.97 seconds
| ProcessVisibility: Foreground
| ProcessState: Running
| WatchdogEvent: scene-create
| WatchdogVisibility: Foreground
| WatchdogCPUStatistics: (
| "Elapsed total CPU time (seconds): 15.290 (user 15.290, system 0.000), 28% CPU",
| "Elapsed application CPU time (seconds): 0.367, 1% CPU"
| )