ios 获取 crash 日志
2015-06-12 21:28
375 查看
#import <Foundation/Foundation.h>
@interface CatchCrash :
NSObject
void uncaughtExceptionHandler(NSException *exception);
@end
#import "CatchCrash.h"
@implementation CatchCrash
void uncaughtExceptionHandler(NSException *exception)
{
// 异常的堆栈信息
NSArray *stackArray = [exception
callStackSymbols];
// 出现异常的原因
NSString *reason = [exception
reason];
// 异常名称
NSString *name = [exception
name];
NSString *exceptionInfo = [NSString
stringWithFormat:@"Exception reason:%@\nException name:%@\nException stack:%@",name,
reason, stackArray];
NSLog(@"crashLog------------%@-------------crashLog", exceptionInfo);
还可以 发送日志我自己哦
// NSString *syserror = [NSString stringWithFormat:@"mailto://595814260@qq.com?subject=bug报告&body=感谢您的配合!<br><br><br>"
// "Error Detail:<br>%@<br>--------------------------<br>%@<br>---------------------<br>%@",
// name,reason,[stackArray componentsJoinedByString:@"<br>"]];
//
//// NSMutableArray *tmpArr = [NSMutableArray arrayWithArray:stackArray];
////
//// [tmpArr insertObject:reason atIndex:0];
// NSURL *url = [NSURL URLWithString:[syserror stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
// [[UIApplication sharedApplication] openURL:url];
//保存到本地 --
当然你可以在下次启动的时候,上传这个log
//[exceptionInfo writeToFile:[NSString stringWithFormat:@"%@/Documents/error.log",NSHomeDirectory()] atomically:YES encoding:NSUTF8StringEncoding error:nil];
}
@end
/// 注册监控
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
}
@interface CatchCrash :
NSObject
void uncaughtExceptionHandler(NSException *exception);
@end
#import "CatchCrash.h"
@implementation CatchCrash
void uncaughtExceptionHandler(NSException *exception)
{
// 异常的堆栈信息
NSArray *stackArray = [exception
callStackSymbols];
// 出现异常的原因
NSString *reason = [exception
reason];
// 异常名称
NSString *name = [exception
name];
NSString *exceptionInfo = [NSString
stringWithFormat:@"Exception reason:%@\nException name:%@\nException stack:%@",name,
reason, stackArray];
NSLog(@"crashLog------------%@-------------crashLog", exceptionInfo);
还可以 发送日志我自己哦
// NSString *syserror = [NSString stringWithFormat:@"mailto://595814260@qq.com?subject=bug报告&body=感谢您的配合!<br><br><br>"
// "Error Detail:<br>%@<br>--------------------------<br>%@<br>---------------------<br>%@",
// name,reason,[stackArray componentsJoinedByString:@"<br>"]];
//
//// NSMutableArray *tmpArr = [NSMutableArray arrayWithArray:stackArray];
////
//// [tmpArr insertObject:reason atIndex:0];
// NSURL *url = [NSURL URLWithString:[syserror stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
// [[UIApplication sharedApplication] openURL:url];
//保存到本地 --
当然你可以在下次启动的时候,上传这个log
//[exceptionInfo writeToFile:[NSString stringWithFormat:@"%@/Documents/error.log",NSHomeDirectory()] atomically:YES encoding:NSUTF8StringEncoding error:nil];
}
@end
/// 注册监控
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
}
相关文章推荐
- MySQL抛出Incorrect string value异常分析
- java程序中的延时加载异常及解决方案
- .NET(C#):Emit创建异常处理的方法
- windows7服务器上weblogic启动失败异常解决方法
- 有关ajax的error与后台的异常问题解决
- 深入探讨JAVA中的异常与错误处理
- iOS开发之路--微博“更多”页面
- GO语言异常处理机制panic和recover分析
- 浅谈JAVA 异常对于性能的影响
- C++ 异常处理 catch(...)介绍
- php中异常处理方法小结
- 浅析Lua编程中的异常处理
- 格式导致的Excel导入sql出现异常的解决方法
- Powershell小技巧之捕获脚本内部的异常
- .NET中的异常和异常处理用法分析
- SQL Server出现System.OutOfMemoryException异常的解决方法
- 简洁实用的Java Base64编码加密异常处理类代码
- java 代码中预防空指针异常的处理办法
- java异常机制分析
- iOS开发之路--微博骨架搭建