wit iOS库会将最后一个未捕获的异常写入文件。当然,在大多数情况下,美观的Crashlytics是最佳选择,但如果您犹豫要不要向代码中添加依赖项,只想跟踪野外的崩溃情况,您可能希望使用更简单的东西。在这种情况下,我编写了这个小巧的库,它安装了一个未捕获异常处理器,将一些(JSON格式)异常信息写入文件——当然,目的是在下次启动后做些事情(如将其发送到您的服务器)。
当你像踢这个一样踢它,你能成为一名目击者吗?(你可以!)
#import "AppDelegate.h"
#import <wit.h>
@implementation AppDelegate
- (BOOL)
application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
wit_install();
return YES;
}
@end
未经捕获的异常使您的应用程序崩溃后,在 tmp/wit.json
中您可以找到
{
"name": "DeliberateException",
"reason": "Deliberately thrown exception to test wit",
"device": {
"version": "7.0.3",
"name": "iPhone OS",
"model": "iPhone Simulator"
},
"stacktrace": [
"0 CoreFoundation 0x017395e4 __exceptionPreprocess + 180",
"1 libobjc.A.dylib 0x014bc8b6 objc_exception_throw + 44",
"2 example 0x00002194 -[ViewController crash:] + 148",
"3 libobjc.A.dylib 0x014ce874 -[NSObject performSelector:withObject:withObject:] + 77",
"4 UIKit 0x0022c0c2 -[UIApplication sendAction:to:from:forEvent:] + 108",
"5 UIKit 0x0022c04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61",
"6 UIKit 0x003240c1 -[UIControl sendAction:to:forEvent:] + 66",
"7 UIKit 0x00324484 -[UIControl _sendActionsForEvents:withEvent:] + 577",
"8 UIKit 0x00323733 -[UIControl touchesEnded:withEvent:] + 641",
"9 UIKit 0x0026951d -[UIWindow _sendTouchesForEvent:] + 852",
"10 UIKit 0x0026a184 -[UIWindow sendEvent:] + 1232",
"11 UIKit 0x0023de86 -[UIApplication sendEvent:] + 242",
"12 UIKit 0x0022818f _UIApplicationHandleEventQueue + 11421",
"13 CoreFoundation 0x016c283f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15",
"14 CoreFoundation 0x016c21cb __CFRunLoopDoSources0 + 235",
"15 CoreFoundation 0x016df29e __CFRunLoopRun + 910",
"16 CoreFoundation 0x016deac3 CFRunLoopRunSpecific + 467",
"17 CoreFoundation 0x016de8db CFRunLoopRunInMode + 123",
"18 GraphicsServices 0x0368e9e2 GSEventRunModal + 192",
"19 GraphicsServices 0x0368e809 GSEventRun + 104",
"20 UIKit 0x0022ad3b UIApplicationMain + 1225",
"21 example 0x0000251d main + 141",
"22 libdyld.dylib 0x01d75725 start + 0",
"23 ??? 0x00000001 0x0 + 1"
],
"date": "11/22/13, 8:39 PM"
}