项目开发过程中经常会遇到crash的问题,现在有比较好的统计工具,但有时我们只是需要了解造成crash的原因,使用友盟等显得有些浪费。现在可以自己动手写记录crash。
ZWCrashRecordTool添加了两个方法:
- 初始化缓存目录
- 清除crash缓存
ZWCrashRecordTool.h
/**
* 初始化缓存目录
*
* @param crashPath 缓存目录
*/
-(void)installUncaughtExceptionHandlerWithPath:(NSString *)crashPath;
/**
* 清除缓存日志
*/
-(void)clearCache;
1、通过installUncaughtExceptionHandlerWithPath:初始化保存目录
2、通过void UncaughtExceptionHandler(NSException *exception)获取crash信息
使用方法
1、初始化方法
在- (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions中加入
method1:
[[ZWCrashRecordTool shareInstance]installUncaughtExceptionHandlerWithPath:nil];
methdo2:
NSString *filePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject;
[[ZWCrashRecordTool shareInstance]installUncaughtExceptionHandlerWithPath:filePath];
2、清除缓存
//清除缓存
[[ZWCrashRecordTool shareInstance] clearCache];