ios获取crash信息

在程序启动代理内加入如下代码:
NSString *applicationDocumentsDirectory() 
{
return  [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; 

}

void UncaughtExceptionHandler(NSException *exception) 
{ 

NSArray *arr = [exception callStackSymbols]; NSString *reason = [exception reason];
NSString *name = [exception name];

NSString *path = [applicationDocumentsDirectory() stringByAppendingPathComponent:@"Exception.txt"];
[urlStr writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil]; 
}

在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 里添加如下:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *path = [applicationDocumentsDirectory() stringByAppendingPathComponent:@"Exception.txt"]; if([fileManager fileExistsAtPath:path]){
NSString *str = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; //读取crash信息 //需要做什么处理在这处理就可以,比如信息上传,
}

[fileManager removeItemAtPath:path error:nil]; //信息处理完事以后进行删除
NSSetUncaughtExceptionHandler (&UncaughtExceptionHandler);
原文地址:https://www.cnblogs.com/leeAsia/p/3363859.html