crash日志收集上传

1.新建工程

https://github.com/Yijijianghu/upload-Crash-Log/tree/master/LogText

导入文件夹 CATLog

app delegate.m 导入头文件

添加方法

@implementation AppDelegate

void uncaughtExceptionHandler(NSException *exception){

[XZLog logCrash:exception];

}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

/***crash日志***/

//Set ExceptionHandler

NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);

// 初始化

[XZLog initLog];

[self uploadCrashLog];

/*****/

return YES;

}



#pragma mark - crash日志

-(void)uploadCrashLog

{

NSLog(@"localFile---->;%@",[self localFile]);

NSLog(@"deviceToken---%@",[UserInfoModel sharedUserInfoModel].currentDeviceToken);

NSLog(@"CurrentSelectedChamber---%@",[[UserInfoModel sharedUserInfoModel]getCurrentSelectedChamber]);

if ([self localFile].length>0)

{

[self uploadCrashnetWork:[self localFile]];

}

}

-(NSString *)localFile{

NSString *docsDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/log"];

NSFileManager *fileManager = [NSFileManager defaultManager];

NSDirectoryEnumerator *dirEnum = [fileManager enumeratorAtPath:docsDir];

NSString *fileName;

NSString *infoStr=[[NSMutableString alloc]init];

while (fileName = [dirEnum nextObject]) {

if ([fileName rangeOfString:@"log"].location !=NSNotFound)

{

NSLog(@"----------FielName : %@" , fileName);

NSLog(@"-----------------FileFullPath : %@" , [docsDir stringByAppendingPathComponent:fileName]) ;

NSString *string = [docsDir stringByAppendingPathComponent:fileName];

NSFileManager *fileManager = [NSFileManager defaultManager];

NSArray *tempFileList = [[NSArray alloc] initWithArray:[fileManager contentsOfDirectoryAtPath:string error:nil]];

NSLog(@"该级文件的子一级文件-%d---%@",(int)tempFileList.count,tempFileList);

NSString *str2=[[NSString alloc]initWithContentsOfFile:string encoding:NSUTF8StringEncoding error:nil];

NSLog(@"读文件=%@====%d",str2,(int)str2.length);

if (![str2 isKindOfClass:[NSNull class]])

{

if (str2.length>0)

{

infoStr=[infoStr stringByAppendingString:str2];

}

}

}

}

if (infoStr.length>0)

{

NSLog(@"infoStr--->:%@",infoStr);

}

return infoStr;

}


infoStr上传服务器

你可能感兴趣的:(crash日志收集上传)