• 请求失败


    // 连接错误报错的方法
    - (void)getErrorMethod:(NSError *)error{
        // 获取当前时间
        NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
        NSString* date = [formatter stringFromDate:[NSDate date]];
        // 获取错误的所在类
        NSString *errorClass = NSStringFromClass([self class]);
        // 获取错误所在的方法
        NSString *errorMethod = NSStringFromSelector(_cmd);
        // 获取错误所在的行数
        NSString *lineNumber = [NSString stringWithFormat:@"%d",__LINE__];
        NSString *excpCnt = [NSString stringWithFormat:
                             @"date: %@ 
     errorClass: %@ 
     errorMethod: %@ 
     lineNumber: %@ 
    
    ",
                             date,errorClass,errorMethod,lineNumber];
        [self saveErrorLog:excpCnt];
    }
    
    
    // 保存日志的方法
    - (void)saveErrorLog:(NSString *)excpCnt{
        NSArray  *dirArr  = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *dirPath = dirArr[0];
        NSString *logDir = [dirPath stringByAppendingString:@"/CrashLog"];
        
        BOOL isExistLogDir = YES;
        NSFileManager *fileManager = [NSFileManager defaultManager];
        if (![fileManager fileExistsAtPath:logDir]) {
            isExistLogDir = [fileManager createDirectoryAtPath:logDir withIntermediateDirectories:YES attributes:nil error:nil];
        }
        if (isExistLogDir) {
            // 此处可扩展
            NSString *logPath = [logDir stringByAppendingString:@"/crashLog.txt"];
            // 没有log.txt文件就新建一个
            if (![fileManager fileExistsAtPath:logPath]) {
                [excpCnt writeToFile:logPath atomically:YES encoding:NSUTF8StringEncoding error:nil];
            }
            // 有的话就追加文字
            else{
                NSFileHandle *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:logPath];
                [fileHandle seekToEndOfFile];  //将节点跳到文件的末尾
                NSData* stringData  = [excpCnt dataUsingEncoding:NSUTF8StringEncoding];
                [fileHandle writeData:stringData]; //追加写入数据
                [fileHandle closeFile];
            }
        }
        
    }
  • 相关阅读:
    Ubuntu部分命令的使用简介
    向Ubuntu的Dash中添加图标
    Ubuntu下实现gedit支持nesC语法高亮
    zoj 1453 Surround the Trees(凸包求周长)
    fzu 1015 土地划分(判断线段相交+求出交点+找规律)
    zoj 1648 判断线段是否相交
    hdu 1086(计算几何入门题——计算线段交点个数)
    zoj 1081 判断点在多边形内
    判点在直线上,三角形内
    poj 1269 Intersecting Lines(判相交交点与平行)
  • 原文地址:https://www.cnblogs.com/zpt1011/p/5316391.html
Copyright © 2020-2023  润新知