Ios app crash的時候經常會顯示一些堆棧資訊:
*** First throw call stack:
(0x2f3a022 0x30cbcd6 0x2ee2a48 0x2ee29b9 0x2f392da 0x9cfd3 0x7f460 0x80a6e 0x103ba29 0x2f05855 0x2f05778 0xf8019a 0x1011c 0x86d5d 0x2f3be99 0x67c14e 0x67c0e6 0x722ade 0x722fa7 0x722266 0x93da1a 0x2f0e99e 0x2ea5640 0x2e714c6 0x2e70d84 0x2e70c9b
0x36d57d8 0x36d588a 0x679626 0x5a45 0x23f5)
terminate called throwing an exception(lldb)
完全看不懂啥意思:有一個辦法可以把他們顯示出來,我在Xcode 4.3, 5.1模擬器上測試確實能顯示
1、在AppDelegate.m加上如下方法:
void uncaughtExceptionHandler(NSException *exception) {
NSLog(@"CRASH: %@", exception);
NSLog(@"Stack Trace: %@", [exception
callStackSymbols]);
// Internal error reporting
}
2、在AppDelegate.m的如下方法第一句話調用如下方法就OK了
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
//其他正常處理
經測試當crash 時能輸出如下log:
Stack Trace: (
0 CoreFoundation 0x02f3a03e __exceptionPreprocess + 206
1 libobjc.A.dylib 0x030cbcd6 objc_exception_throw + 44
2 CoreFoundation 0x02ee2a48 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x02ee29b9 +[NSException raise:format:] + 57
4 CoreFoundation 0x02f392da -[__NSCFDictionary setObject:forKey:] + 250
5 MyAppName 0x0009cfd3 -[XXXDetailView initWithData:frame:type:] + 4051