ios中线上或者内部测试bug统计收集有两种方法:
1)使用第三方bug收集
1.bugHD
来源http://bughd.com/doc/ios-customize
2.bugtags
来源http://help.bugtags.com/hc/kb/article/124400/
http://help.bugtags.com/hc/kb/article/68482/
3.KSCrash
https://github.com/kstenerud/KSCrash
4.友盟
主要不要多种一起使用,使用多个崩溃收集第三方会导致NSSetUncaughtExceptionHandler()函数指针的恶意覆盖,导致有些第三方不能收到崩溃信息
2)自己搭建后台收集bug
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler); return YES; } void UncaughtExceptionHandler(NSException *exception) { /** * 获取异常崩溃信息 */ NSArray *callStack = [exception callStackSymbols]; NSString *reason = [exception reason]; NSString *name = [exception name]; NSString *content = [NSString stringWithFormat:@"========异常错误报告======== name:%@ reason: %@ callStackSymbols: %@",name,reason,[callStack componentsJoinedByString:@" "]]; /** * 把异常崩溃信息发送至开发者邮件 */ NSMutableString *mailUrl = [NSMutableString string]; [mailUrl appendString:@"mailto:test@qq.com"]; [mailUrl appendString:@"?subject=程序异常崩溃,请配合发送异常报告,谢谢合作!"]; [mailUrl appendFormat:@"&body=%@", content]; // 打开地址 NSString *mailPath = [mailUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailPath]]; }
NSSetUncaughtExceptionHandler只能监听NSException类型的异常,而引起崩溃的大多数原因如:内存访问错误,重复释放等错误就无能为力了。因为这种错误它抛出的是Signal,
所以必须要专门做Signal处理, 可以参考如下封装;测试时,可以调用abort()函数,模拟发送SIGABRT信号,不要联机测试,要脱机测试。
参考:http://www.cnblogs.com/easonoutlook/archive/2012/12/27/2835979.html
http://blog.csdn.net/qianlima210210/article/details/51226087
https://github.com/easonoutlook/UncaughtExceptionHandler
从iOS设备导出的bug日志大概是这样的:
// 1.进程信息 Incident Identifier: 4CBF22C2-3E92-434B-B5DF-C35CF670B007 CrashReporter Key: 1a0da8d4b693f98613cf29e3a42e503ffa91d9fb Hardware Model: iPhone7,2 Process: ********** [1895] Path: /private/var/containers/Bundle/Application/1096962B-8F33-4BA5-8101-C733C98D3E2F/**********.app/********** Identifier: ********** Version: 21500 (2.1.5) Code Type: ARM-64 (Native) Parent Process: launchd [1] // 2.基本信息 Date/Time: 2017-03-02 09:59:59.59 +0800 Launch Time: 2017-03-02 09:59:59.59 +0800 OS Version: iOS 9.3.2 (13F69) Report Version: 105 // 3.异常信息 Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Exception Note: EXC_CORPSE_NOTIFY Triggered by Thread: 0 Filtered syslog: None found Last Exception Backtrace: 0 CoreFoundation 0x182df6db0 __exceptionPreprocess + 124 1 libobjc.A.dylib 0x18245bf80 objc_exception_throw + 56 2 CoreFoundation 0x182cda708 -[__NSArrayM insertObject:atIndex:] + 808 3 *************** 0x100123c50 -[AppDelegate application:didFinishLaunchingWithOptions:] (AppDelegate.m:49) 4 UIKit 0x187fca9c0 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 400 5 UIKit 0x1881fa184 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2904 6 UIKit 0x1881fe5f0 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1684 7 UIKit 0x1881fb764 -[UIApplication workspaceDidEndTransaction:] + 168 8 FrontBoardServices 0x1847977ac __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36 9 FrontBoardServices 0x184797618 -[FBSSerialQueue _performNext] + 168 10 FrontBoardServices 0x1847979c8 -[FBSSerialQueue _performNextFromRunLoopSource] + 56 11 CoreFoundation 0x182dad09c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 12 CoreFoundation 0x182dacb30 __CFRunLoopDoSources0 + 540 13 CoreFoundation 0x182daa830 __CFRunLoopRun + 724 14 CoreFoundation 0x182cd4c50 CFRunLoopRunSpecific + 384 15 UIKit 0x187fc394c -[UIApplication _run] + 460 16 UIKit 0x187fbe088 UIApplicationMain + 204 17 *************** 0x10017a5ec main (main.m:14) 18 libdyld.dylib 0x1828728b8 start + 4 Global Trace Buffer (reverse chronological seconds): 6148914688.535940 CFNetwork 0x000000018347bf18 TCP Conn 0x12dd91c60 complete. fd: 8, err: 0 6148914688.536304 CFNetwork 0x000000018347d444 TCP Conn 0x12dd91c60 event 1. err: 0 6148914688.549507 CFNetwork 0x000000018347d51c TCP Conn 0x12dd91c60 started 6148914688.550894 CFNetwork 0x00000001834d7e5c Creating default cookie storage with default identifier 6148914688.550894 CFNetwork 0x00000001834d7e28 Faulting in CFHTTPCookieStorage singleton 6148914688.550894 CFNetwork 0x0000000183529e50 Faulting in NSHTTPCookieStorage singleton // 4.线程回调 Thread 0 name: Dispatch queue: com.apple.main-thread // 5.线程状态 Thread 0 Crashed: 0 libsystem_kernel.dylib 0x000000018299011c __pthread_kill + 8 1 libsystem_pthread.dylib 0x0000000182a5cef8 pthread_kill + 112 2 libsystem_c.dylib 0x0000000182901dac abort + 140 3 libc++abi.dylib 0x00000001824353f4 __cxa_bad_cast + 0 4 libc++abi.dylib 0x0000000182451e98 default_unexpected_handler() + 0 5 libobjc.A.dylib 0x000000018245c248 _objc_terminate() + 124 6 libc++abi.dylib 0x000000018244ef44 std::__terminate(void (*)()) + 16 7 libc++abi.dylib 0x000000018244eb10 __cxa_rethrow + 144 8 libobjc.A.dylib 0x000000018245c120 objc_exception_rethrow + 44 9 CoreFoundation 0x0000000182cd4cf8 CFRunLoopRunSpecific + 552 10 UIKit 0x0000000187fc394c -[UIApplication _run] + 460 11 UIKit 0x0000000187fbe088 UIApplicationMain + 204 12 *********************** 0x000000010017a5ec main (main.m:14) 13 libdyld.dylib 0x00000001828728b8 start + 4 Thread 1 name: Dispatch queue: NSOperationQueue 0x12dd6d5e0 :: NSOperation 0x12ded4110 (QOS: LEGACY) Thread 1: 0 libsystem_kernel.dylib 0x000000018298f140 __bsdthread_ctl + 8 1 libsystem_pthread.dylib 0x0000000182a5eb10 _pthread_set_properties_self + 64 2 Foundation 0x00000001837b2b20 iop_set_pthread + 200 3 Foundation 0x00000001837b2890 __NSOQSchedule_f + 60 // 6.二进制映像 Binary Images: 0x100088000 - 0x1002d7fff *********************** arm64 <da83a4ffedd937bd93e8313b34363457> /var/containers/Bundle/Application/1096962B-8F33-4BA5-8101-C733C98D3E2F/***********************.app/*********************** 0x100630000 - 0x100657fff MagicalRecord arm64 <6bcc1202aef333e5b1c7c62443f57b2a> /var/containers/Bundle/Application/1096962B-8F33-4BA5-8101-C733C98D3E2F/***********************.app/Frameworks/MagicalRecord.framework/MagicalRecord
1.查看 xx.app 文件的 UUID,terminal 中输入命令 :
dwarfdump --uuid xx.app/xx (xx代表你的项目名)
2.查看 xx.app.dSYM 文件的 UUID ,在 terminal 中输入命令:
dwarfdump --uuid xx.app.dSYM
3.crash 文件内第一行 Incident Identifier 就是该 crash 文件的 UUID。
.crash文件的分析
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
b.输出bug信息
symbo xx.crash xx.dSYM ->bug.txt
参考:http://www.cocoachina.com/ios/20141219/10694.html
https://github.com/answer-huang/dSYMTools